Skip to content

Speed up handing filtered circles to the map - #49

Merged
wf9a5m75 merged 3 commits into
developfrom
perf/circle-handoff
Nov 21, 2026
Merged

wf9a5m75 merged 3 commits into
developfrom
perf/circle-handoff

Conversation

@wf9a5m75

@wf9a5m75 wf9a5m75 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Speeds up handing a large circle list to the map after a filter change. On the antenna sample (723,800 circles), turning a carrier off or on took 5.7–6.2 s in Release from tap to onAddEnd. Drawing the tiles was not the slow part: all 16 tiles finished within 0.3 s, and the slowest took about 0.1 s. Almost all the time went to the hand-over before them.

What

  1. Circle tiler: a list is matched against the registered states by object identity and revision, which changes on every write.
    • States that did not change are not read again.
    • A filter only turns their slots on or off. Before, checking that nothing changed took 3.4–4.3 s, and deciding whether each state can be tiled took 1.2 s.
    • A state written to between lists is read again.
  2. OverlayCollector: who joined or left is found by marking each member with a pass number, not by building sets of ids. This was 1.4 s on the main thread. No public API change.
  3. onAddStart / onAddEnd:
    • The tracker compares the next list with the last one by identity, and builds ids only for states that joined or left. This was 0.5–1.0 s on the main thread.
    • Fixed: onAddEnd could come right after onAddStart, followed by a second onAddStart. This happened because the tracker could settle before the tiler started.
      • Circle, polyline and polygon controllers now count as drawing from the start of their add.
      • A settle timer that fires more than 100 ms late (a blocked main thread) waits again.

12 tests added; all 578 pass. One test writes to a circle between two filters, and checks that the new geometry is drawn. Breaking the revision check makes it fail.

Checked

Antenna sample on an iPad Pro 11-inch, Google Maps, toggling Verizon. Tap to onAddEnd:

Verizon off Verizon on Main thread blocked
develop, Release 5.7 s 6.2 s 1.3–1.7 s
this PR, Release 0.95 s 1.2 s 0.33–0.39 s
develop, Debug 11.4 s 12.9 s 2.6–3.0 s
  • The last tile is drawn 0.55–0.6 s after the tap (develop: 5.3–5.8 s).
  • Screenshots show Verizon hidden and shown again correctly.
  • Each toggle calls exactly one onAddStart and one onAddEnd.

The sample-side change is MapConductor/ios-sdk#35.

A carrier toggle in the antenna sample (723,800 circles) spent 5.5 s on an
iPad Pro (Debug) in the circle tiler before the map got new tiles, nearly
all of it reading the properties of circles that had not changed:
3.4-4.3 s comparing each with the stored geometry, 1.2 s deciding again
whether it can be tiled, 0.7 s reading and sorting zIndex.

- ShapeTileSet keeps, per slot, the state registered there and its
  revision (which moves on every write). registeredSlots(_:) matches a list
  to the slots by identity and revision, walking both in order, so a
  registered and unchanged circle is known without reading it.
- ShapeTiler.route tiles known circles without canTile, and passes their
  slots to setStates. A list of known circles in the registered order is
  shown by switching slots on and off (reuseCircleSlots); otherwise known
  circles give their zIndex from the slot and skip the comparison with the
  file. A list already in zIndex order is not sorted.
- A slot left out by a filter keeps its state (sourceActive says which are
  drawn), so the state can be matched to it again when it comes back.
- The tiler hands the map the template before building the id set, which
  is bookkeeping.

ShapeTiler and ShapeTileSet now take class states only, as all three
users are.
Syncing a changed list of 723,800 circles took 1.4 s on the main thread
(iPad Pro, Debug): two sets of ids, a dictionary, and a new closure for
every state.

Each state's StateMutationSignal now holds a listener object, Member,
which keeps the pass of sync(_:) the state was last listed in. A sync
moves the listed states to the new pass; a state of the last list still on
the old pass has left and stops listening; a state without our member has
joined. Members are kept across syncs, so nothing is allocated for states
that stay. The id dictionary for get(_:) and values() is built when asked
for.

The public API is unchanged: listen(_:) wraps its closure. A write from
another thread now reaches the collector on the main thread.
- AddProgressTracker compared lists with two sets of ids: 0.5-1.0 s on the
  main thread for 723,800 circles. It now walks the new and the last list
  side by side by identity, scanning ahead once past a run of removed
  states, and looks ids up only for objects that did not line up (a new
  object with an id that left is an update, not a new state).
- onAddEnd could come right after onAddStart for a list that only removed
  states: the hand-over held the main thread past the settle delay, and the
  tiler had not started yet. The controllers now keep the tiler busy from
  the start of add until the route has handed the map the tiles, and a
  settle timer that fires late (the main thread was held) waits once more.
- CircleController forgets ids the app dropped after the route instead of
  before it, so the map gets the tiles sooner.
@wf9a5m75
wf9a5m75 merged commit a3dc641 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