Closed casperisfine closed 5 years ago
Which memory profiler were you running? I’ve got a branch for a value pool implementation that would benefit from this, and I’d be able to compare interning vs value pool for both performance and memory.
I can’t accept this PR as is, because this change would require a hard bump of version to 4.0 since I still officially support Ruby 2.1 and higher.
This could be handled by adding a class function MIME::Types.intern(string)
that is implemented differently for Ruby versions that support String#@-
and those that don’t.
This could be handled by adding a class function
MIME::Types.intern(string)
that is implemented differently for Ruby versions that supportString#@-
and those that don’t.
Indeed, I totally missed the 2.1 support.
I have a string interner implementation I used on another project, I can update this PR to fallback to it on pre 2.5.
Which memory profiler were you running?
https://github.com/SamSaffron/memory_profiler it has a few bugs, but it's decent enough.
I can update this PR to fallback to it on pre 2.5.
Or alternatively, I can simply not intern anything on pre 2.5. It's already how 2.4 and 2.5 passe CI. String#-@
freeze the strings, but don't really intern anything.
Let me know which you prefer, but IMHO I don't think it's worth lots of effort to save memory on very old versions.
I pushed a new commit as to not break if interning is not available.
I will release this update in the near future. Thanks for the contribution!
👋 sorry to bother, but is there anything blocking a release I could help with?
Unfortunately, it’s mostly my time. I’ll try to get something soon. Sorry for the delay.
No worries, I know how it is.
Released.
❤️ Thanks a lot!
While running a memory profiler against our app, I noticed mime-types was holding onto a lot of duplicated strings:
The idea here is to apply
String#@-
to as much as possible deduplicate these strings.Note that regardless of wether they are duplicates or not, they will be frozen (which IMO is a good thing).