#57781·rails

Strong increase in allocations in web UIs that use ViewComponents after d24d0b7187b6568d76972d61ce91eea698503797

Author: issyl0Created Jun 19, 2026Updated Sep 12, 2026
Labelsregressionactionpack

We deployed Rails 8.2.0.alpha.4b53ec0 including https://github.com/rails/rails/pull/50623 and saw a strong increase (50%+ on some pages) in the number of allocations on web UI pages with lots of ViewComponent usage.

We did some non-expert analysis and profiling and we think it's related to that PR because it's newly hitting render_template.action_view for every component where it didn't before.

Steps to reproduce

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org/"

  gem "view_component"

  # gem "rails", github: "rails/rails", ref: "343fe92bd24c9660c90e5107ea34c72915bda865"
  # D, [2026-06-19T07:23:50.690103 #71282] DEBUG -- :   Rendering /var/folders/b1/zsr0hbcn19xcqy26gq0blks80000gn/T/d20260619-71282-3r0n44/index.html.erb
  # I, [2026-06-19T07:23:50.692031 #71282]  INFO -- :   Rendered /var/folders/b1/zsr0hbcn19xcqy26gq0blks80000gn/T/d20260619-71282-3r0n44/index.html.erb (Duration: 1.7ms | GC: 0.0ms)

  gem "rails", github: "rails/rails", ref: "f26f56ed4e19dea9119fcfe067eff36b7f0b5dc5"
  # D, [2026-06-19T07:24:41.672509 #71907] DEBUG -- :   Rendering /var/folders/b1/zsr0hbcn19xcqy26gq0blks80000gn/T/d20260619-71907-9ozdat/index.html.erb
  # D, [2026-06-19T07:24:41.677087 #71907] DEBUG -- :   Rendering MyComponent
  # I, [2026-06-19T07:24:41.677900 #71907]  INFO -- :   Rendered MyComponent (Duration: 0.7ms | GC: 0.0ms)
  # D, [2026-06-19T07:24:41.677961 #71907] DEBUG -- :   Rendering MyComponent
  # I, [2026-06-19T07:24:41.678011 #71907]  INFO -- :   Rendered MyComponent (Duration: 0.0ms | GC: 0.0ms)
  # D, [2026-06-19T07:24:41.678056 #71907] DEBUG -- :   Rendering MyComponent
  # I, [2026-06-19T07:24:41.678097 #71907]  INFO -- :   Rendered MyComponent (Duration: 0.0ms | GC: 0.0ms)
  # I, [2026-06-19T07:24:41.678130 #71907]  INFO -- :   Rendered /var/folders/b1/zsr0hbcn19xcqy26gq0blks80000gn/T/d20260619-71907-9ozdat/index.html.erb (Duration: 5.6ms | GC: 0.0ms)

  # Note the extra logging for rendering MyComponent. (Those logs aren't enabled
  # in production, but I think we're still subscribed to render_template.action_view
  # via the structured event subscriber and our view component usage is heavy
  # enough that it's causing a large increase in allocations on some pages.)
end

require "action_controller/railtie"
require "action_view/railtie"
require "view_component"
require "minitest/autorun"

class TestApp < Rails::Application
  config.load_defaults Rails::VERSION::STRING.to_f
  config.eager_load = false
  config.logger = Logger.new($stdout)
  config.secret_key_base = "secret_key_base"
end
Rails.application.initialize!

class MyComponent < ViewComponent::Base
  erb_template <<~ERB
    <p>HELLO WORLD<\p>
  ERB
end

class BugTest < ActionView::TestCase
  setup do
    @view_path = Pathname.new(Dir.mktmpdir)
    ActionController::Base.prepend_view_path @view_path
  end

  teardown do
    @view_path.rmtree
  end

  def test_action_view_render_template
    view_file "index.html.erb", <<~ERB
      <%= render MyComponent.new %>
      <%= render MyComponent.new %>
      <%= render MyComponent.new %>
    ERB

    render template: "index"

    assert_equal "HELLO WORLD", rendered.html.at("p").text
  end

  private
    def view_file(filename, contents)
      pathname = @view_path.join(filename)
      pathname.dirname.mkpath
      pathname.write(contents.chomp)
    end
end

Expected behavior

Allocations should remain stable on web UIs.

Actual behavior

Allocations increase significantly on some pages heavy with ViewComponents. This graph was where we first spotted the increase in allocations during the deploy.

System configuration

Rails version: 8.2.0.alpha.4b53ec0

Ruby version: 4.0.5