Skip to content

Do not scan to the end for each new state spread through a list - #50

Merged
wf9a5m75 merged 1 commit into
developfrom
fix/add-progress-spread-states
Nov 21, 2026
Merged

wf9a5m75 merged 1 commit into
developfrom
fix/add-progress-spread-states

Conversation

@wf9a5m75

Copy link
Copy Markdown
Contributor

Fixes a main-thread freeze introduced in #49. Toggling carriers one after another in the antenna sample (723,800 circles) stopped the main thread for 3 to 10 s.

Why

AddProgressTracker.compare walks the next list against the last one, and looks up to 64 states ahead for each object. Past that, it scanned on to the end of the last list.

  • When a carrier comes back, its cells are spread through the list. Each new cell scanned to the end of the last list, so the cost grew with the square of the list size.
  • Verizon's cells are in one run, so the toggle measured in Speed up handing filtered circles to the map #49 did not show this. AT&T and T-Mobile toggles do.

What

The walk scans past the window until it has scanned as many states as the last list has. After that, it looks objects up in an index of the last list, keyed by ObjectIdentifier and built once. The cost stays linear in the list size.

  • A run of new states, and a filter that drops long runs, still never build the index.
  • An object found behind the cursor through the index now counts as matched. Before, it counted as both new and removed, and the id comparison sorted it out. The result is the same either way.

One test added: 20,000 new states spread through a 60,000-state list. It passes; with the old scan put back, it fails. All 579 tests pass.

Checked

On an iPad Pro 11-inch with Google Maps, Release build: 20 taps across the four carriers, about 0.8 s apart, without waiting for the app to go idle.

Longest main-thread stall List comparison
develop 9.7 s up to 9.4 s
this PR 0.46 s 56–175 ms

After the taps, the sample shows all 723,800 circles and the drawing overlay is gone.

A carrier that comes back in the antenna sample brings its cells all
over the list. compare scanned the rest of the last list for each of
them, and toggling carriers in a row held the main thread for 3 to 10 s
on an iPad Pro. Once it has scanned as many states as the last list
has, it now looks objects up in an index of that list.
@wf9a5m75
wf9a5m75 merged commit 69b5fa1 into develop Nov 21, 2026
2 checks passed
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.

1 participant