Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid loading ActionController::Base when rendering mail #45144

Conversation

jonathanhefner
Copy link
Member

This avoids unnecessarily loading ActionController::Base when rendering mail after Action Text has been loaded.

Before:

$ bin/rails r 'Benchmark.memory { |x| x.report("load"){ MyBlankMailer.blank_email.body } }'
Calculating -------------------------------------
                load    12.679M memsize (     1.927M retained)
                       101.143k objects (    19.947k retained)
                        50.000  strings (    50.000  retained)

After:

$ bin/rails r 'Benchmark.memory { |x| x.report("load"){ MyBlankMailer.blank_email.body } }'
Calculating -------------------------------------
                load     7.678M memsize (     1.302M retained)
                        61.420k objects (    13.644k retained)
                        50.000  strings (    50.000  retained)

This is based on top of #45142. See the 2nd commit (c2a3ff0) for the relevant change.

This refactor avoids unnecessarily loading `ActionController::Base` when
loading `ActionMailer::Base`.

Before:

```
$ bin/rails r 'Benchmark.memory { |x| x.report("load"){ ActionMailer::Base } }'
Calculating -------------------------------------
                load    10.013M memsize (     1.372M retained)
                        78.341k objects (    14.363k retained)
                        50.000  strings (    50.000  retained)
```

After:

```
$ bin/rails r 'Benchmark.memory { |x| x.report("load"){ ActionMailer::Base } }'
Calculating -------------------------------------
                load     5.043M memsize (   729.741k retained)
                        38.854k objects (     7.809k retained)
                        50.000  strings (    50.000  retained)
```
This avoids unnecessarily loading `ActionController::Base` when
rendering mail after Action Text has been loaded.

Before:

```
$ bin/rails r 'Benchmark.memory { |x| x.report("load"){ MyBlankMailer.blank_email.body } }'
Calculating -------------------------------------
                load    12.679M memsize (     1.927M retained)
                       101.143k objects (    19.947k retained)
                        50.000  strings (    50.000  retained)
```

After:

```
$ bin/rails r 'Benchmark.memory { |x| x.report("load"){ MyBlankMailer.blank_email.body } }'
Calculating -------------------------------------
                load     7.678M memsize (     1.302M retained)
                        61.420k objects (    13.644k retained)
                        50.000  strings (    50.000  retained)
```
@byroot byroot merged commit 815f282 into rails:main May 21, 2022
jonathanhefner added a commit to jonathanhefner/rails that referenced this pull request Sep 23, 2022
Follow-up to rails#45144.

This ensures that a renderer is always available for Action Text, even
when `ActionController::Base` was not previously loaded.

Fixes rails#46113.

As with rails#45144, this still avoids loading `ActionController::Base`
unnecessarily when rendering mail after Action Text has been loaded.

**Before:**

```
$ bin/rails r 'Benchmark.memory { |x| x.report("load"){ MyBlankMailer.blank_email.body } }'
Calculating -------------------------------------
                load     4.466M memsize (     1.205M retained)
                        29.202k objects (    11.943k retained)
                        50.000  strings (    50.000  retained)
```

**After:**

```
$ bin/rails r 'Benchmark.memory { |x| x.report("load"){ MyBlankMailer.blank_email.body } }'
Calculating -------------------------------------
                load     4.462M memsize (     1.205M retained)
                        29.141k objects (    11.940k retained)
                        50.000  strings (    50.000  retained)
```

Co-authored-by: Christopher Louvet <cl@nonplaces.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants