Skip to content

perf: Skip lifecycle processing work when the queue is empty - #3978

Merged
spydon merged 3 commits into
mainfrom
perf/lifecycle-queue-early-out
Aug 16, 2026
Merged

perf: Skip lifecycle processing work when the queue is empty#3978
spydon merged 3 commits into
mainfrom
perf/lifecycle-queue-early-out

Conversation

@spydon

@spydon spydon commented Aug 5, 2026

Copy link
Copy Markdown
Member

Description

processLifecycleEvents now returns immediately when the queue is empty instead of allocating a set and a closure on every tick, the reorder-parents set is only allocated when a priority change is actually queued, and the blocked-set hash lookups are skipped while the set is empty (the common single-pass case).

Extracted from #3960 so the data-structure change there stands alone (as requested in this comment). Behavior is unchanged; this only removes per-tick allocations and lookups from the game loop.

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

Comment thread packages/flame/lib/src/components/core/component_tree_root.dart Outdated
Comment thread packages/flame/lib/src/components/core/component_tree_root.dart Outdated
Comment thread packages/flame/lib/src/components/core/component_tree_root.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.

LGTM, I am not convinced of the isNotEmpty skip but leave it to you

Comment thread packages/flame/lib/src/components/core/component_tree_root.dart Outdated
@spydon
spydon force-pushed the perf/lifecycle-queue-early-out branch from cab5f6b to 29a82f1 Compare August 16, 2026 13:25
@spydon
spydon merged commit e2fe200 into main Aug 16, 2026
8 checks passed
@spydon
spydon deleted the perf/lifecycle-queue-early-out branch August 16, 2026 13:43
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