uap-ruby
uap-ruby copied to clipboard
Memory optimization
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 thank you for your PR! Seems like freeze is not supported on the older ruby versions.
Ah right, I forgot to check for support.
Done.