Skip to content

perf: Replace generator-based removal teardown with an explicit collection pass - #3981

Open
spydon wants to merge 1 commit into
perf/lazy-render-contextsfrom
perf/removal-teardown-buffer
Open

perf: Replace generator-based removal teardown with an explicit collection pass#3981
spydon wants to merge 1 commit into
perf/lazy-render-contextsfrom
perf/removal-teardown-buffer

Conversation

@spydon

@spydon spydon commented Aug 5, 2026

Copy link
Copy Markdown
Member

Description

The removal teardown walked the subtree through the recursive descendants sync* generator, allocating generator frames per tree level on every component removal. It now collects the subtree into a reusable buffer (same leaves-first order) and iterates that.

Extracted from #3960 so the data-structure change there stands alone (as requested in this comment). Stacked on #3980.

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/removal-teardown-buffer branch from 4276a39 to 237d786 Compare August 5, 2026 20:18
},
includeSelf: true,
);
final buffer = _teardownBuffer.isEmpty ? _teardownBuffer : <Component>[];

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.

is allocating one empty list per component removal that significant? feels like this static cache is introducing potential future concurrency problems or hard to find headaches. seems that major gain here is the non-generator teardown and not the brittle [] cache?

);
final buffer = _teardownBuffer.isEmpty ? _teardownBuffer : <Component>[];
_collectTeardown(buffer);
for (var i = 0; i < buffer.length; i++) {

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.

please don't say that dart's built-in for each has some hidden performance cost too 😵‍💫

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