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 adds the template file to the template_globs array of the Primer::Forms::ActAsComponent module (source), which is then used in compile! in the included ActAsComponent module to compile the templates before rendering (source).
The problem is that compile! is called each time Primer::Forms::BaseComponent#compile_and_render_template is called (source) which happens every time a component is rendered (source).
I confirmed it by adding a p template_globs in #renders_templates. The printed list keeps growing on each rendering.
It's not a big memory leak, but the problem becomes noticeable in development: because templates are always recompiled in dev, and the template list is ever growing, the same template gets compiled multiple times which eventually slows down the application.
I noticed it as I was waiting for more than 1 second for a simple page update. This was confirmed in the application logs:
D, [2025-01-10T14:48:30.157985 #37009] DEBUG -- : ↳ app/forms/work_packages/dialogs/create_form.rb:63:in `block (2 levels) in <class:CreateForm>'
I, [2025-01-10T14:48:31.238213 #37009] INFO -- : Completed 200 OK in 1131ms (Views: 0.0ms | ActiveRecord: 10.7ms | Allocations: 3158630)
After a restart, on first request:
D, [2025-01-10T16:14:44.258971 #46501] DEBUG -- : ↳ app/forms/work_packages/dialogs/create_form.rb:63:in `block (2 levels) in <class:CreateForm>'
I, [2025-01-10T16:14:44.310702 #46501] INFO -- : Completed 200 OK in 261ms (Views: 0.1ms | ActiveRecord: 108.5ms | Allocations: 233774)
To sum up numbers:
On startup: 0,052 seconds for rendering and 233 774 allocations
After using the app for a while: 1,080 seconds for rendering (+1,028) and 3 158 630 allocations (+2 924 856)
Replacing the array with a Set in app/lib/primer/forms/acts_as_component.rb fixes the issue
def template_globs
@template_globs ||= Set.new
end
But maybe you'd prefer fixing it another way, like calling renders_template only once at class initialization.
The text was updated successfully, but these errors were encountered:
In
Primer::Forms::BaseComponent
, each time#compile!
is called, it calls this line:This adds the template file to the
template_globs
array of thePrimer::Forms::ActAsComponent
module (source), which is then used incompile!
in the includedActAsComponent
module to compile the templates before rendering (source).The problem is that
compile!
is called each timePrimer::Forms::BaseComponent#compile_and_render_template
is called (source) which happens every time a component is rendered (source).I confirmed it by adding a
p template_globs
in#renders_templates
. The printed list keeps growing on each rendering.It's not a big memory leak, but the problem becomes noticeable in development: because templates are always recompiled in dev, and the template list is ever growing, the same template gets compiled multiple times which eventually slows down the application.
I noticed it as I was waiting for more than 1 second for a simple page update. This was confirmed in the application logs:
After a restart, on first request:
To sum up numbers:
Replacing the array with a
Set
inapp/lib/primer/forms/acts_as_component.rb
fixes the issueBut maybe you'd prefer fixing it another way, like calling
renders_template
only once at class initialization.The text was updated successfully, but these errors were encountered: