Skip to content

perf: Insertion-sort the sweep broadphase and swap-remove its active list - #3983

Merged
spydon merged 7 commits into
mainfrom
perf/sweep-insertion-sort
Aug 16, 2026
Merged

perf: Insertion-sort the sweep broadphase and swap-remove its active list#3983
spydon merged 7 commits into
mainfrom
perf/sweep-insertion-sort

Conversation

@spydon

@spydon spydon commented Aug 5, 2026

Copy link
Copy Markdown
Member

Description

Sweep.update re-sorted its items with a full List.sort and a closure comparator every tick, although the list is nearly sorted between ticks (hitboxes only move a little per frame); an insertion sort makes that near-linear. Sweep.query also pruned its active list with a searching List.remove; since active-list order does not matter, that is now an O(1) swap-remove.

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

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/collisions/broadphase/sweep/sweep.dart Outdated
@spydon
spydon force-pushed the perf/sweep-insertion-sort branch from ef353a5 to a676a48 Compare August 16, 2026 13:25
@spydon
spydon force-pushed the perf/sweep-insertion-sort branch from 1fe301b to 4dbea34 Compare August 16, 2026 15:05
@spydon
spydon changed the base branch from perf/pointer-handler-early-out to perf/removal-teardown-buffer August 16, 2026 15:06
Base automatically changed from perf/removal-teardown-buffer to main August 16, 2026 15:38
…sort

# Conflicts:
#	packages/flame/lib/src/components/core/component.dart

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

Perfect

@spydon
spydon merged commit 55eaec4 into main Aug 16, 2026
8 checks passed
@spydon
spydon deleted the perf/sweep-insertion-sort branch August 16, 2026 16:02
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