From c39f969dd2a901edfb4d0f61f5b520a03e52f879 Mon Sep 17 00:00:00 2001 From: Rainer Borene Date: Thu, 19 Oct 2023 17:52:20 -0300 Subject: [PATCH] fix: reduce UnboundMethod objects by memoizing initialize_parameters (#1868) Co-authored-by: Cameron Dutro --- docs/CHANGELOG.md | 4 ++++ lib/view_component/base.rb | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 4e38e7784..65d856715 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -18,6 +18,10 @@ nav_order: 5 *Alexandre Ignjatovic* +* Reduce UnboundMethod objects by memoizing initialize_parameters + + *Rainer Borene* + * Improve docs about inline templates interpolation. *Hans Lemuet* diff --git a/lib/view_component/base.rb b/lib/view_component/base.rb index 9dd3944af..0bdee95af 100644 --- a/lib/view_component/base.rb +++ b/lib/view_component/base.rb @@ -553,6 +553,7 @@ def identifier # @param parameter [Symbol] The parameter name used when rendering elements of a collection. def with_collection_parameter(parameter) @provided_collection_parameter = parameter + @initialize_parameters = nil end # Strips trailing whitespace from templates before compiling them. @@ -648,7 +649,7 @@ def initialize_parameter_names end def initialize_parameters - instance_method(:initialize).parameters + @initialize_parameters ||= instance_method(:initialize).parameters end def provided_collection_parameter