Skip to content

Hand bulk collections over as a list, and track collector listeners by pass - #57

Merged
wf9a5m75 merged 2 commits into
developfrom
perf/overlay-state-list
Nov 21, 2026
Merged

wf9a5m75 merged 2 commits into
developfrom
perf/overlay-state-list

Conversation

@wf9a5m75

Copy link
Copy Markdown
Contributor

Stacked on #56, which is stacked on #54. Merge those first; this one then retargets.

Pairs with MapConductor/android-sdk-compose (Circles list hand-over), which needs the OverlayStateList added here.

Why

After #56 the antenna sample (723,800 circles, Pixel 5a) still took 11–14 s from a carrier toggle to the last tile. Most of what remained was the compose hand-over through the collector's persistent map:

step time
Circles merging its list into a copy of the persistent map (removing 147k, putting 576k) ~1.8 s
collector's listener pass on the main thread (an id lookup per state in the other map) ~1.7 s
values.toList() in CircleOverlay ~0.35 s

Merely iterating a PersistentOrderedMapBuilder of 576k entries takes about 0.44 s, because it looks the next key up at each step.

What

Two commits:

  1. Pass token. The collector listens through a PassToken replaced at every pass.
    • A state in the new map moves to the current token.
    • A state of the old map still on an older token of this collector was not in the new one, and stops.
    • Telling which states left takes one read per state and no lookups. An id is still looked up for a state not yet listening here.
  2. OverlayStateList. A MutableMap over the list a collection was given.
    • Iterating it walks the list. Only a key lookup builds an index (a LinkedHashMap, built on first use).
    • The collector's pass and CircleOverlay.render walk the list, and the overlay hands the list itself to the controller. OverlayAddedTracker gets the ids lazily.
    • A write heard through the latest pass's token is known to come from a member without a lookup.
    • As with every published generation, the map is not to be written to. One that is written to follows its index.

No public API change. OverlayStateList and PassToken are @InternalMapConductorApi, and apiCheck passes. flow keeps its type, so readers that look ids up still work, at the cost of building the index once.

Measured (with the compose PR, same toggle, Pixel 5a, 3 runs)

step before this PR after
Circles effect to published 3.6–6.0 s 0.74–0.80 s
collector pass (main thread) 1.2–1.7 s 0.13–0.14 s
tap to last tile drawn 9.9–14.0 s 6.6–7.2 s (≈20 s before #56)

The pass-token commit alone took the pass to 1.23–1.29 s. The iteration cost above is the part only the list hand-over removes.

Checked

  • :android-sdk-core:testDebugUnitTest: 451 pass. New tests:
    • a bulk list that drops and restores states keeps the rest reporting;
    • a list hand-over reports writes of its states only;
    • a written list follows its index.
  • apiCheck passes.
  • On the device:
    • carrier off/on/off gives 576,636 → 723,800 → 351,201 circles;
    • the Alaska remount (dispose and re-create) draws and keeps the selection;
    • no crash.

listenToWrittenStates looked every id of the new map up in the old one
and every id of the old map up in the new one: about 1.7 s on the main
thread for the 576k/724k circles of the antenna sample on a Pixel 5a.

The collector now listens through a PassToken replaced at every pass. A
state in the new map is moved to the current token; a state of the old
map still on an older token of this collector was not in the new one,
and stops. One read per state, no lookups; an id is still looked up for
a state not yet listening here, to stop what held that id before.

The pass is now 1.2-1.3 s. Of that, merely iterating the
PersistentOrderedMapBuilder is about 0.44 s per 576k entries (it looks
the next key up at each step), which only a different hand-over can
avoid.
A collector's membership is a MutableMap, and for a bulk collection that
map was a PersistentOrderedMap of every state: building it took about
1.8 s per hand-over for the antenna sample's 576k circles on a Pixel 5a,
and merely iterating it about 0.44 s per pass (it looks the next key up
at each step), on the collector's pass and the overlay's toList.

OverlayStateList is a MutableMap over the list a collection was given:
iterating it walks the list, and only a key lookup builds an index. The
collector's listener pass and CircleOverlay walk the list; the overlay
hands the list itself to the controller, and the added-tracker gets the
ids lazily. A write from the latest pass's token is known to be from a
member without a lookup.

A published map is still not to be written to; one that is follows its
index. The ids must be distinct (the compose Circles hands a list over
only when they are).
@wf9a5m75
wf9a5m75 changed the base branch from perf/tile-reuse-snapshot to develop November 21, 2026 09:31
@wf9a5m75
wf9a5m75 merged commit 312867e into develop Nov 21, 2026
2 of 3 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