Skip to content

Commit 08e937c

Browse files
committed
Update benchmarks to render more than a single time
Previously we would render a single component or a single partial from a controller context to benchmark performance. This is valid, but isn't as realistic as rendering more components/partials inside the rendering path. This updates the benchmarks to render multiple of the renderer type being benchmarked in an attempt to get closer to simulating a real page load. * Updates both components to render another component 50 times * Updates partial to render another partial 50 times
1 parent 541ddf9 commit 08e937c

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed
+12-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
# frozen_string_literal: true
22

33
class Performance::InlineComponent < ViewComponent::Base
4-
def initialize(name:)
4+
def initialize(name:, nested: true)
55
@name = name
6+
@nested = nested
67
end
78

89
def call
910
# rubocop:disable Rails/OutputSafety
10-
"<h1>hello #{@name}</h1>".html_safe
11+
content = "<h1>hello #{@name}</h1>".html_safe
12+
13+
if @nested
14+
safe_join([
15+
content,
16+
50.times.map { InlineComponent.new(name: @name, nested: false) }
17+
])
18+
else
19+
content
20+
end
1121
end
1222
end
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
<h1>hello <%= @name %></h1>
2+
3+
<% if @nested %>
4+
<% 50.times do %>
5+
<%= render Performance::NameComponent.new(name: @name, nested: false) %>
6+
<% end %>
7+
<% end %>
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# frozen_string_literal: true
22

33
class Performance::NameComponent < ViewComponent::Base
4-
def initialize(name:)
4+
def initialize(name:, nested: true)
55
@name = name
6+
@nested = nested
67
end
78
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>nested hello <%= name %></p>
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
<h1>hello <%= name %></h1>
2+
3+
<% 50.times do %>
4+
<%= render 'nested', name: name, nested: false %>
5+
<% end %>

0 commit comments

Comments
 (0)