perf: Make render contexts and debug caches lazily allocated - #3980
Open
spydon wants to merge 1 commit into
Open
perf: Make render contexts and debug caches lazily allocated#3980spydon wants to merge 1 commit into
spydon wants to merge 1 commit into
Conversation
spydon
force-pushed
the
perf/lazy-render-contexts
branch
from
August 5, 2026 20:18
14664ba to
78c0fe6
Compare
luanpotter
reviewed
Aug 7, 2026
| final context = renderContext; | ||
| if (context != null) { | ||
| _renderContexts.add(context); | ||
| (_renderContexts ??= []).add(context); |
Member
There was a problem hiding this comment.
can we do final renderContexts = _renderContexts ??= []; at the top to avoid the ! later?
Member
There was a problem hiding this comment.
also wanna do the const [] trick?
luanpotter
reviewed
Aug 7, 2026
| if (hasContext) { | ||
| originalLength = child._renderContexts.length; | ||
| child._renderContexts.addAll(_renderContexts); | ||
| final contexts = _renderContexts; |
Member
There was a problem hiding this comment.
could also be the same
final renderContexts = _renderContexts ?? const [];
so you don't have to null check or fallback below?
luanpotter
approved these changes
Aug 7, 2026
luanpotter
left a comment
Member
There was a problem hiding this comment.
Makes sense to me, just a couple comments about structure and avoiding !
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.
Description
Every
Componenteagerly allocated aQueueListfor render contexts plus two debug-paintValueCaches. The context stack is now a lazily created plain list (most components never provide or receive a render context) and the debug caches arelate final, so plain components allocate none of them.Extracted from #3960 so the data-structure change there stands alone (as requested in this comment). Stacked on #3979.
Checklist
docsand added dartdoc comments with///.examplesordocs.Breaking Change?
Related Issues
Relates to #3957