Skip to content

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

Merged
spydon merged 2 commits into
mainfrom
perf/lazy-render-contexts
Aug 16, 2026
Merged

perf: Make render contexts and debug caches lazily allocated#3980
spydon merged 2 commits into
mainfrom
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

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?

Comment thread packages/flame/lib/src/components/core/component.dart Outdated

@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 !

@spydon
spydon force-pushed the perf/lazy-render-contexts branch from 78c0fe6 to 6262ecd Compare August 16, 2026 13:25
@spydon
spydon force-pushed the perf/lazy-render-contexts branch from 3f2d31f to 9baaf38 Compare August 16, 2026 13:43
@spydon
spydon force-pushed the perf/lazy-render-contexts branch from 9baaf38 to 08d67cf Compare August 16, 2026 14:39
Base automatically changed from perf/render-closure-caching to main August 16, 2026 14:52
@spydon
spydon force-pushed the perf/lazy-render-contexts branch from 08d67cf to 264fc66 Compare August 16, 2026 14:52
@spydon
spydon merged commit 8f6bb04 into main Aug 16, 2026
8 checks passed
@spydon
spydon deleted the perf/lazy-render-contexts branch August 16, 2026 15:05
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