You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This preallocates a `DEFAULT_ENV` Rack env for `Renderer` instances to
use, and avoids `dup`ing the `DEFAULTS` Hash unless the user intends to
modify it. This reduces retained allocations per controller class.
**Benchmark**
```ruby
# frozen_string_literal: true
require "benchmark/memory"
$controllers = []
Benchmark.memory do |x|
Class.new(ActionController::Base) # warmup
x.report("1 controller") do
$controllers << Class.new(ActionController::Base)
end
x.report("100 controllers") do
100.times { $controllers << Class.new(ActionController::Base) }
end
end
```
**Before**
```
Calculating -------------------------------------
1 controller 16.070k memsize ( 9.683k retained)
133.000 objects ( 40.000 retained)
50.000 strings ( 14.000 retained)
100 controllers 1.607M memsize ( 875.044k retained)
13.300k objects ( 3.308k retained)
50.000 strings ( 50.000 retained)
```
**After**
```
Calculating -------------------------------------
1 controller 15.654k memsize ( 9.347k retained)
129.000 objects ( 38.000 retained)
49.000 strings ( 14.000 retained)
100 controllers 1.565M memsize ( 841.284k retained)
12.900k objects ( 3.108k retained)
50.000 strings ( 50.000 retained)
```
This does add a `dup` to `render` because `request.routes = ...` mutates
the underlying env, which can now be `DEFAULT_ENV`. But a temporary
allocation there (likely outside of a request cycle) seems like a
reasonable trade for avoiding two retained allocations per controller
class.
0 commit comments