uap-ruby icon indicating copy to clipboard operation
uap-ruby copied to clipboard

Memory optimization

Open casperisfine opened this issue 3 years ago • 3 comments

regexes.yaml contains quite a lot of duplicated strings. By passing freeze: true to YAML.load we allow the parser to deduplicate them.

Additionally, the regexes source and flags are never used, so they can be removed from the long lived hashes.

Before:

Total allocated: 3.47 MB (28214 objects)
Total retained: 1.45 MB (8422 objects)

After:

Total allocated: 3.71 MB (30218 objects)
Total retained: 1.24 MB (4583 objects)

It's not a big difference in size, but it cuts down in half the number of objects than need to be marked by the GC.

casperisfine avatar Jun 27 '22 11:06 casperisfine

@casperisfine thank you for your PR! Seems like freeze is not supported on the older ruby versions.

opti avatar Jul 07 '22 10:07 opti

Ah right, I forgot to check for support.

casperisfine avatar Jul 07 '22 13:07 casperisfine

Done.

casperisfine avatar Jul 07 '22 13:07 casperisfine