Skip to content

Reduce allocations in Slotable#register_default_slots #2328

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

Merged
merged 2 commits into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ nav_order: 6

## main

* Reduce string allocations during compilation.

*Jonathan del Strother*

## 3.23.2

* Include .tt files in published gem. Fixes templates not being available when using generators.
Expand Down
3 changes: 2 additions & 1 deletion lib/view_component/slotable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ def register_polymorphic_slot(slot_name, types, collection:)
# Called by the compiler, as instance methods are not defined when slots are first registered
def register_default_slots
registered_slots.each do |slot_name, config|
config[:default_method] = instance_methods.find { |method_name| method_name == :"default_#{slot_name}" }
default_method_name = :"default_#{slot_name}"
config[:default_method] = instance_methods.find { |method_name| method_name == default_method_name }

registered_slots[slot_name] = config
end
Expand Down
4 changes: 2 additions & 2 deletions test/sandbox/test/rendering_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def test_render_inline_allocations
if Rails.version.to_f < 8.0
{"3.3.8" => 124, "3.3.0" => 140, "3.2.8" => 122, "3.1.7" => 122, "3.0.7" => 131}
elsif Rails.version.split(".").first(2).map(&:to_i) == [8, 0]
{"3.5.0" => 117, "3.4.4" => 121, "3.3.8" => 133}
{"3.5.0" => 117, "3.4.4" => 121, "3.4.3" => 121, "3.3.8" => 133}
else
{"3.4.4" => 119}
{"3.4.4" => 119, "3.4.3" => 119}
end

assert_allocations(**allocations) do
Expand Down
Loading