Repository navigation
Stop rendering once render_block has its block - #1053
Open
patrick-immometrica wants to merge 1 commit into
Open
patrick-immometrica wants to merge 1 commit into
patrick-immometrica wants to merge 1 commit into
Conversation
render_block rendered the whole template into a sink and only kept the requested block, so everything after the block was evaluated for nothing. Blocks can't be inside loops and their names are unique, so once the block is captured nothing later can change it and we can unwind straight away.
patrick-immometrica
marked this pull request as ready for review
October 24, 2026 21:13
This branch has not been deployed
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.
render_blockinterprets the whole template intoio::sink()and keeps the requested block fromblock_buffer. Everything after the block, often the bulk of the page, is still evaluated and then thrown away.Block names are unique and the parser doesn't allow blocks inside for loops, so once the requested block has been rendered nothing that follows can change it. This sets a flag on the state when the block is captured, and the
RenderBlockarm returns right after it, which unwinds through any outer blocks too.One behaviour change: an error that only happens after the block (an undefined variable further down, say) no longer fails
render_block. I think that's what you'd expect when asking for one block, and it's what the new test checks, for a plain template, a nested block and a child template usingsuper(). An error inside the block itself still surfaces.Before/after for a template with a small header block followed by a 2,000-row loop (release build, µs per call, three runs):
render_block("page.html", "header")render("page.html")Full renders don't change; the spread there is just noise.