-
-
Notifications
You must be signed in to change notification settings - Fork 283
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
Reduce string allocations and retentions #580
Conversation
Thanks @casperisfine , this looks great. Are you able to share some insights about the allocation improvement? |
@weppos I'd need to re-run the profile with this gem patched. It would take ~20m. However I'm confident all these duplications will disappear as I already did some very similar PR on several gems. But tell me and I can trigger a profile. |
Ok, so I just ran the profile anyway. These strings are effectively gone from the retained string reports as expected. As for the overall impact, the total retained memory difference is that this branch retain That being said the baseline was using |
Ok, so compared to 7f67e4e: Retained memory: So I'd say it's a decent saving. |
Oh, I just figured you were asking about allocations vs retention. I totally forgot to explain to allocation part: On master:
That is why I added the magic comment on the top of the file, this way it saves 4k allocations of Looking at the overall allocation savings I see a |
Ok, yeah the difference come from on having some cache loaded, while the other was fresh, so simply ignore that. The actual allocation reduction should be is before: after: So a bit over 500KB saved. |
Sweet, thanks! ❤️ |
Shipped 4.1.0 |
While running
memory_profiler
agaisnt our app, I noticed quite a lot of duplicated strings coming from whois:So here's I'm trying to reduce these duplications as to reclaim a bit of memory. The whole thing rely on
String#-@
which starting in MRI 2.5 will freeze and possibly intern the string.On 2.4 and older (or some oldish alternative implementation) it will fallback to simply freezing the string, so no memory will be saved, but for the caller the string will still be frozen so that should prevent any kind of weirdness when upgrade the ruby version.