micke / valid_email2

ActiveModel validation for email. Including MX lookup and disposable email blacklist
MIT License
658 stars 102 forks source link

Loading Mail Parsers takes a lot of memory #165

Open schneems opened 4 years ago

schneems commented 4 years ago

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("developer@example.com")
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

dogweather commented 3 years ago

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.

micke commented 3 years ago

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!