mail icon indicating copy to clipboard operation
mail copied to clipboard

Lazy-load fields and elements

Open c960657 opened this issue 2 years ago • 0 comments

Even though there are autoload rules specified for (nearly) all field classes, these are eager-loaded by require 'mail'. This defeats some of the purpose with using autoload.

I have used this little script to see how many files are included:

module Kernel
  alias_method :old_require, :require

  def require(file)
    loaded = old_require(file)
    puts file if loaded
    loaded
  end
end

$LOAD_PATH.unshift "#{__dir__}/lib"
require 'mail'

This PR removes the explicit loading files in lib/mail/fields and lib/mail/elements. This reduces the number files initially required from 95 to 42. The loading of these files is postponed until this gem is actually used to send a mail.

The performance impact of this is tiny, but if you use many gems, it all adds up.

c960657 avatar Jun 16 '22 14:06 c960657