Skip to content

perf: Make render contexts and debug caches lazily allocated - #3980

Open
spydon wants to merge 1 commit into
perf/render-closure-cachingfrom
perf/lazy-render-contexts
Open

perf: Make render contexts and debug caches lazily allocated#3980
spydon wants to merge 1 commit into
perf/render-closure-cachingfrom
perf/lazy-render-contexts

Conversation

@spydon

@spydon spydon commented Aug 5, 2026

Copy link
Copy Markdown
Member

Description

Every Component eagerly allocated a QueueList for render contexts plus two debug-paint ValueCaches. The context stack is now a lazily created plain list (most components never provide or receive a render context) and the debug caches are late 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

  • I have followed the Contributor Guide when preparing my PR.
  • [-] I have updated/added tests for ALL new/updated/fixed functionality.
  • [-] I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • [-] I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

Related Issues

Relates to #3957

@spydon
spydon force-pushed the perf/lazy-render-contexts branch from 14664ba to 78c0fe6 Compare August 5, 2026 20:18
final context = renderContext;
if (context != null) {
_renderContexts.add(context);
(_renderContexts ??= []).add(context);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do final renderContexts = _renderContexts ??= []; at the top to avoid the ! later?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also wanna do the const [] trick?

if (hasContext) {
originalLength = child._renderContexts.length;
child._renderContexts.addAll(_renderContexts);
final contexts = _renderContexts;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could also be the same

final renderContexts = _renderContexts ?? const [];

so you don't have to null check or fallback below?

@luanpotter luanpotter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me, just a couple comments about structure and avoiding !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants