Skip to content

Let marker controllers hear writes without a Combine subscription each - #51

Merged
wf9a5m75 merged 1 commit into
developfrom
perf/marker-change-listener
Nov 21, 2026
Merged

wf9a5m75 merged 1 commit into
developfrom
perf/marker-change-listener

Conversation

@wf9a5m75

Copy link
Copy Markdown
Contributor

Switching the provider on the street trees page (144,183 markers) froze the screen for 6.4–6.5 s on an iPad Pro. Each provider's marker controller subscribed to every marker's asFlow() on the main thread. That took 3.5 s for the new map, and the old map took 1.8–2.0 s to cancel its subscriptions.

What

  • MarkerState.onChange(_:) (@_spi(MapConductorDriver)) calls a closure on the main queue after each write to the marker. It goes through the state's StateMutationSignal, the same way OverlayCollector hears writes for circles, polylines and polygons. It costs one allocation per marker.
    • There is no call on subscribe; the first call comes with the first write. This matches asFlow().dropFirst().
    • A marker has one listener, as a state in an OverlayCollector does, and the newest listener hears the writes. Cancelling a token whose listener has since been replaced leaves the newer one alone. A provider switch relies on this, because the old map is taken down after the new one has listened.
  • MarkerIngestionEngine no longer reads and converts the icon of a marker that is tiled; only a native marker uses it.

3 tests added; all 582 pass. The replaced-listener test fails if cancelling clears the listener unconditionally.

The provider controllers move to onChange in PRs of the same branch name in the 10 provider repos.

Checked

On an iPad Pro 11-inch, Release build, street trees page, switching MapLibre ⇄ Google:

before after
New map's controller subscribes 3.5 s 0.13–0.15 s
Old map's controller cancels 1.8–2.0 s 0.17 s
Ingestion 0.8 s 0.7 s
Main thread blocked 6.4–6.5 s 1.19–1.27 s

Marker writes still reach the map after a switch. At zoom 16 and above the page writes label icons onto markers. Screenshots show the following:

  • Labels appear on Google.
  • After switching to MapLibre at zoom 15, they are cleared.
  • They appear again at zoom 16 on MapLibre.
  • They are still there back on Google.

MarkerState.onChange calls a closure on the main queue after each write,
through the state's StateMutationSignal. Switching the provider on the
street trees page (144,183 markers) held the main thread for 6.5 s on an
iPad Pro: 3.5 s subscribing the new map's controller to every marker's
asFlow(), 2 s cancelling the old one's. With onChange, 0.15 s and 0.17 s.

Ingestion no longer reads and converts the icon of a marker that is
tiled; only a native marker uses it.
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