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

Switch to mini_mime for memory savings #1059

Closed
wants to merge 2 commits into from

Conversation

SamSaffron
Copy link
Contributor

@SamSaffron SamSaffron commented Dec 14, 2016

The mime types gem (even with the magical columnar store by @jeremyevans) is a memory hog.

In particular on boot, mime/types/columnar will allocate 109k objects and end up with a retained count of 31K objects.

This bloat leaves objects that need to be marked and swept every major GC and bloats ruby processes.

To circumvent mini_mime was created.

It uses the exact same database as the full fledged mime types and is capable of only loading stuff on demand with a practical, safe and bound in-memory cache.

mini_mime will allocate 398 objects on boot and only retain 62 (due to rubygems inefficiency)

In table form:

boot allocations boot retained lookup lookup uncached
mini_mime 398 62 641K/s 33K/s
mime-types 109796 31165 361K/s 361K/s

The performance of mini_mime is pretty good, cached lookups are faster than the mime types gem and uncached lookups are 10x slower. (which is really not at huge issue considering the memory savings)

…_mime

Also

- Explicit support for Ruby 1.8 and 1.9 is removed
- Appraisal gem no longer needed as it was testing for mime types gem
@mperham
Copy link
Contributor

mperham commented Dec 14, 2016

my hero

@SamSaffron
Copy link
Contributor Author

FYI did a similar PR to rest-client

rest-client/rest-client#557

@radar
Copy link
Contributor

radar commented Dec 14, 2016

This is great! Thank you @SamSaffron.

Is there any particular reason why you're removing the older versions of Ruby from the travis config? Seems out of scope for this PR.

@SamSaffron
Copy link
Contributor Author

SamSaffron commented Dec 14, 2016

@radar it was a bit fiddly to remove the giant matrix of mime types tests and this seemed like the simplest way to resolve, when I removed stuff and left the rake hack in the Gemfile, it had issues bundling.

supporting 1.8 or 1.9 seems very very bad these days ... 1.9 has no support or security patches for almost 2 years.

ultimately it is your call if to support 1.8 but would appreciate some help figuring out an appropriate Gemfile hack here.

@jeremy jeremy added this to the 2.7.0 milestone Dec 14, 2016
@jeremy
Copy link
Collaborator

jeremy commented Dec 14, 2016

Squashed with #1060 and merged @ 634d911 🖖

@jeremy jeremy closed this Dec 14, 2016
@jeremy jeremy changed the title FEATURE: remove the dependency on the mime types use mini_mime Switch to mini_mime for memory savings Dec 14, 2016
@czj
Copy link

czj commented Dec 14, 2016

Thanks a lot. Ruby and Rails need this kind of optimisation !

@schneems
Copy link

Sam you are the mini_* master 😎

@stereobooster
Copy link

stereobooster commented Mar 8, 2017

Am I missing something or it is not released yet? https://rubygems.org/gems/mail/

VERSIONS:
2.6.4 - March 23, 2016 (344 KB)

RUNTIME DEPENDENCIES (1):
mime-types < 4, >= 1.16

@jeremy jeremy mentioned this pull request May 17, 2017
carlosantoniodasilva added a commit to carlosantoniodasilva/httparty that referenced this pull request Nov 10, 2022
`mini_mime` is a minimal mime type library that's more performant and
less memory hungry.
https://github.com/discourse/mini_mime

It has replaced `mime-types` in the `mail` gem: (which is a dependency
of `actionmailer`, and by extension, `rails`)
mikel/mail#1059

As well as `capybara`:
teamcapybara/capybara#1884

Which also means using it as a dependency of `httparty` would be able to
reuse the same dependency that should be already available in most Rails
apps, instead of pulling in an extra `mime-types` dependency.

The change in code is pretty straightforward, the same one made by the
capybara PR linked above.
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

7 participants