Skip to content

Enable warning on shape too complex #2258

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions performance/components/complex_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>hello <%= @name %></h1>

<% 50.times do %>
<%= render Performance::NestedComplexComponent.new(name: @name) %>
<% end %>
8 changes: 8 additions & 0 deletions performance/components/complex_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Performance::ComplexComponent < ViewComponent::Base
def initialize(name:)
('a'...'z').to_a.shuffle.each do |c|
instance_variable_set("@rand_var_#{c}", true)
end
@name = name
end
end
3 changes: 3 additions & 0 deletions performance/components/name_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

class Performance::NameComponent < ViewComponent::Base
def initialize(name:)
('a'...'z').to_a.each do |c|
instance_variable_set("@rand_var_#{c}", true)
end
@name = name
end
end
1 change: 1 addition & 0 deletions performance/components/nested_complex_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>nested hello <%= @name %></p>
10 changes: 10 additions & 0 deletions performance/components/nested_complex_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class Performance::NestedComplexComponent < ViewComponent::Base
def initialize(name:)
('a'...'z').to_a.shuffle.each do |c|
instance_variable_set("@rand_var_#{c}", true)
end
@name = name
end
end
3 changes: 3 additions & 0 deletions performance/components/nested_name_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

class Performance::NestedNameComponent < ViewComponent::Base
def initialize(name:)
('a'...'z').to_a.each do |c|
instance_variable_set("@rand_var_#{c}", true)
end
@name = name
end
end
11 changes: 9 additions & 2 deletions performance/partial_benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

require "benchmark/ips"

Warning[:performance] = true

# Configure Rails Environment
ENV["RAILS_ENV"] = "production"
require File.expand_path("../test/sandbox/config/environment.rb", __dir__)
Expand All @@ -13,6 +15,8 @@ module Performance
require_relative "components/name_component"
require_relative "components/nested_name_component"
require_relative "components/inline_component"
require_relative "components/complex_component"
require_relative "components/nested_complex_component"
end

class BenchmarksController < ActionController::Base
Expand All @@ -21,13 +25,16 @@ class BenchmarksController < ActionController::Base
BenchmarksController.view_paths = [File.expand_path("./views", __dir__)]
controller_view = BenchmarksController.new.view_context

controller_view.render(Performance::ComplexComponent.new(name: "HI there"))

Benchmark.ips do |x|
x.time = 10
x.warmup = 2

x.report("component") { controller_view.render(Performance::NameComponent.new(name: "Fox Mulder")) }
x.report("inline") { controller_view.render(Performance::InlineComponent.new(name: "Fox Mulder")) }
x.report("partial") { controller_view.render("partial", name: "Fox Mulder") }
# x.report("inline") { controller_view.render(Performance::InlineComponent.new(name: "Fox Mulder")) }
# x.report("partial") { controller_view.render("partial", name: "Fox Mulder") }
x.report("complex") { controller_view.render(Performance::ComplexComponent.new(name: "Fox Mulder")) }

x.compare!
end
2 changes: 2 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
require "simplecov-console"
require "rails/version"

Warning[:performance] = true

if ENV["MEASURE_COVERAGE"]
SimpleCov.start do
command_name "minitest-rails#{Rails::VERSION::STRING}-ruby#{RUBY_VERSION}"
Expand Down
Loading