Repository navigation
Reduce allocation overhead of #50623 - #1
Closed
joelhawksley wants to merge 1 commit into
Closed
joelhawksley wants to merge 1 commit into
joelhawksley wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
render_inarity +respond_to?(:format)prepend_formatswhen subsetTemplateRendererperRendererNotifications.listening?gateTemplate::Renderablewhen no block