ActionMailbox uses lots of RAM although not in use - how to remove?

Is there a way to remove ActionMailbox from my Rails app? I’m getting out of memory errors with Rails 6, and derailer shows action_mailbox as the lead memory hog — even though my app doesn’t use it:

TOP: 116.9336 MiB
  rails/all: 62.0156 MiB
    action_mailbox/engine: 35.7305 MiB
1 Like

When using rails new --skip-action-mailbox it comments out the line require "action_mailbox/engine" in config/application.rb:

So I’d try replacing require "rails/all" with this:

require "active_record/railtie"
require "active_storage/engine"
require "action_controller/railtie"
require "action_view/railtie"
require "action_mailer/railtie"
require "active_job/railtie"
require "action_cable/engine"
# require "action_mailbox/engine"
require "action_text/engine"
require "rails/test_unit/railtie"
require "sprockets/railtie"
2 Likes

Excellent - great idea.

I think this is an issue. I love how Rails gives you everything out-of-the-box, but the price to pay to have actionmailbox already included is too high. 30MB loaded in memory is not an irrelevant amount.

1 Like

We can quickly verify that it does use a lot of memory when there are a lot of Person records being created!

Yep, this is a solution for skipping it, but does anybody know why Action Mailbox, in particular, takes so much memory?

This knowledge may be out-of-date, but at one point in time, the reason why ActionMailbox uses so much memory is:

ActionMailbox relies upon the Mail gem to parse emails. The Mail gem parses emails by creating several state machines with Ragel, which works by creating big arrays of integers which is the source of the memory usage.

You can dig into this write-up for more info: https://www.schneems.com/2014/11/07/i-ram-what-i-ram.html

And here is some of the work that looks like it wasn’t completed to reduce the memory usage of mail parsing: address_lists_parser.rb requires a lot of memory (~30 mb) · Issue #1342 · mikel/mail · GitHub