valid_email2 icon indicating copy to clipboard operation
valid_email2 copied to clipboard

Loading Mail Parsers takes a lot of memory

Open schneems opened this issue 4 years ago • 2 comments

See this line: https://github.com/micke/valid_email2/blob/3ff4c929e54ecb701f952219de81726d29fbfe80/lib/valid_email2/address.rb#L26

If you run this script you'll see that loading parsers from the Mail gem requires a LOT of memory:

require 'mail'
require 'get_process_mem'

before = GetProcessMem.new.mb
address = Mail::Address.new("[email protected]")
address.domain
after = GetProcessMem.new.mb

puts "Enabling email parsing requires #{after - before} mb of memory"
# => Enabling email parsing requires 30.9296875 mb of memory

Just throught you should know. Also since the call usually happens at run time instead of load time it's 30mb of memory use for every process.

Here's a discussion on the issue and a proposed (but not accepted) alternative

  • Issue: https://github.com/mikel/mail/issues/1342#issuecomment-498793055 (closed, but it's still a known problem)
  • Alternative: https://github.com/mikel/mail/pull/1343

schneems avatar Sep 17 '20 19:09 schneems

Suggestion: somehow enable the user to choose whether to optimize for speed (current version) or memory (proposed change). That is, instead of trying to please everyone or making these optimization decisions ahead of time. :-)

My use case: A Rails app which only occasionally sends email and never receives it. But every instance pays the 30+ MB price, making it difficult to run efficiently on a PaaS, Heroku.

dogweather avatar Feb 07 '21 20:02 dogweather

Hi, sorry for not attending to this earlier!

I like the idea, and would prefer the default behaviour to use the mail gem. I currently have no spare time to put into this feature, but i would gladly accept a PR!

micke avatar Feb 07 '21 22:02 micke