Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory optimization #104

Merged
merged 1 commit into from Aug 24, 2022
Merged

Conversation

casperisfine
Copy link
Contributor

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.

@opti
Copy link
Collaborator

opti commented Jul 7, 2022

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

@casperisfine
Copy link
Contributor Author

Ah right, I forgot to check for support.

@casperisfine
Copy link
Contributor Author

Done.

`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.
@opti opti merged commit acc3bdf into ua-parser:main Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants