mime-types/ruby-mime-types

Decrease memory usage

jeremyevans opened this issue · 1 comments

As discussed at RubyConf, the mail gem uses only a small part of the information provided by mime-types, but has to pay the memory penalty for loading mime-types, which is over twice as much memory as that taken by the rest of the mail library.

As mail only needs a small part of the information that mime-types provides, I wrote a patch to mail that extracts only the information from mime-types that mail uses, resulting in a 2/3 reduction in the amount of memory used (see mikel/mail#829). But this has compatibility issues because it can't support the same API that mime-types offers to add types at runtime (Mime::Type.register). So it's either going to require a major version bump for mail, and dropping the dependency on mime-types, or finding some way to reduce the amount of memory used by mime-types.

We discussed various ways to reduce the amount of memory that mime-types uses, such as only loading parts that are needed without loading the entire data set, or storing the information in a file-based database.

Anyway, I'm opening this ticket so we can discuss possible ideas/implementations for reducing memory usage in mime-types.

Why don't you have major categories of mime types stored in separate ruby files and allow users to load only specific ones into the global types array as required?