Skip to content
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

* Measure cache digest precomputation in the boot benchmark by disabling class reloading in the benchmark app and having each generated component render another.

*Joel Hawksley*

* Add a CI performance check that fails a pull request when any benchmark scenario's component/partial render-time ratio, or ViewComponent's share of app boot time, regresses by more than 5% against the base branch on Rails 8.1 or Rails main.

*Joel Hawksley*
Expand Down
1 change: 1 addition & 0 deletions performance/boot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
class BootApp < Rails::Application
config.root = ARGV.fetch(0)
config.load_defaults Rails::VERSION::STRING.to_f
config.cache_classes = true
config.eager_load = true
config.secret_key_base = "performance"
config.logger = Logger.new(nil)
Expand Down
16 changes: 13 additions & 3 deletions performance/measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,17 @@ class BenchmarksController < ActionController::Base
components = File.join(root, "app", "components")
FileUtils.mkdir_p(components)

# Each component renders another, so boot also discovers cache digest dependencies.
render_call = lambda do |i|
case i % 3
when 0 then "render Sidecar#{i}Component.new(name: 'x')"
when 1 then "render(Inline#{i}Component.new) { 'x' }"
else "render Slots#{i}Component.new"
end
end

Integer(ENV.fetch("BOOT_COMPONENTS", 300)).times do |i|
rendered = render_call.call(i.zero? ? 1 : (i - 1) / 2)
case i % 3
when 0
File.write(File.join(components, "sidecar#{i}_component.rb"), <<~RUBY)
Expand All @@ -131,11 +141,11 @@ def initialize(name:)
end
end
RUBY
File.write(File.join(components, "sidecar#{i}_component.html.erb"), "<p><%= @name %></p>\n")
File.write(File.join(components, "sidecar#{i}_component.html.erb"), "<p><%= @name %></p><%= #{rendered} %>\n")
when 1
File.write(File.join(components, "inline#{i}_component.rb"), <<~RUBY)
class Inline#{i}Component < ViewComponent::Base
erb_template "<p><%= content %></p>"
erb_template "<p><%= content %></p><%= #{rendered} %>"
end
RUBY
else
Expand All @@ -145,7 +155,7 @@ class Slots#{i}Component < ViewComponent::Base
renders_many :items
end
RUBY
File.write(File.join(components, "slots#{i}_component.html.erb"), "<%= header %><% items.each do |item| %><%= item %><% end %>\n")
File.write(File.join(components, "slots#{i}_component.html.erb"), "<%= header %><% items.each do |item| %><%= item %><% end %><%= #{rendered} %>\n")
end
end

Expand Down
Loading