Visitar URL original
Reduce allocation overhead of #50623 by joelhawksley · Pull Request #1 · joelhawksley/rails · GitHub
Skip to content

Reduce allocation overhead of #50623 - #1

Closed
joelhawksley wants to merge 1 commit into
mainfrom
joelhawksley-expert-disco
Closed

joelhawksley wants to merge 1 commit into
mainfrom
joelhawksley-expert-disco

Conversation

@joelhawksley

Copy link
Copy Markdown
Owner

Problem

rails#50623 closed a long-present gap between the render pipeline for renderables and non-renderables. GitHub saw a significant increase in allocations on ViewComponent-heavy routes as a result.

Alternative solution

@seanpdoyle proposed walking back most of the changes in https://github.com/rails/rails/compare/seanpdoyle:issue-57781. While I think that is an acceptable fix (and one we should land if this PR is not accepted), I would rather try to optimize the current implementation so we can keep the rendering of renderables as close to the same as non-renderables.

Proposed solution

Benchmarks are for renders with no subscribers to render_template.action_view.

I found a handful of optimizations that get us down to 10 obj/render, when we had 4 obj/render before rails#50623. @seanpdoyle's proposed fix is 8 obj/render. I think it's worth the extra two objects to have a much more unified approach.

Scenario Objects/render
Pre-rails#50623 (main @ 343fe92) 4
Post-rails#50623 (main today) 19
+ memoize render_in arity + respond_to?(:format) 15
+ skip prepend_formats when subset 14
+ reuse TemplateRenderer per Renderer 13
+ caller-side Notifications.listening? gate 12
+ pool Template::Renderable when no block 10
seanpdoyle bypass fix 8

PR rails#50623 introduced a ~5x per-render allocation regression for objects
rendered via render(renderable) because every such call now flows through
the full template rendering pipeline. This restores most of the previous
throughput while keeping renderables' rendering path unified with regular
templates.

Fixes rails#57781.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 3ec82d0c-59bb-4b6a-8ef2-8f6edb8967ea
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant