Skip to content

Keep CircleController.add's id walks off the main thread - #59

Merged
wf9a5m75 merged 1 commit into
developfrom
perf/circle-add-off-main
Nov 21, 2026
Merged

wf9a5m75 merged 1 commit into
developfrom
perf/circle-add-off-main

Conversation

@wf9a5m75

Copy link
Copy Markdown
Contributor

On a Pixel 5a, every carrier toggle on the antenna sample (723,800 circles, all drawn as tiles) blocked the main thread for about 0.6 s.

Why

After the tiler takes a list, CircleController.add does two walks on the map's thread:

  1. It filters the list against the tiled ids, to find the circles drawn natively.
  2. It walks the previously tiled ids, to drop the ones that left.

With hundreds of thousands of tiled circles, both are 720k hash lookups on the main thread.

What

  • When every circle is tiled, the filter is skipped. The sizes can match only then, because the tiled ids come from the list and each id is tiled once.
  • Otherwise, the filter runs on Dispatchers.Default.
  • The walk over previously tiled ids also runs on Dispatchers.Default. CircleManager keeps its entities in a ConcurrentHashMap, and add already registers tiled entities from Dispatchers.Default.

All 451 android-sdk-core unit tests pass.

Checked

A/B on a Pixel 5a, Google Maps, antenna sample: 8 Verizon toggles, 9 s apart, on a fresh launch, two runs per build. The build was non-debuggable, with project dependencies.

develop this PR
Tap to onAddEnd (mean) 4.05 s 3.40 s
Longest main-thread stall per toggle (mean) 0.96 s 0.47 s
Total main-thread stall per toggle (mean) 1.04 s 0.56 s

Most of what remains is the main thread waiting on garbage collection: WaitForGcToComplete blocked Alloc for 0.6–1.4 s. The app runs at 390–480 MB of heap with all the circles loaded.

After the tiler took a list, add() filtered the list against the tiled
ids and walked the previously tiled ids on the map's thread. Over the
antenna sample's 723,800 tiled circles that held it for about 0.6 s per
carrier toggle on a Pixel 5a. Both walks now run on Dispatchers.Default,
and when every circle is tiled the filter is skipped.
@wf9a5m75
wf9a5m75 merged commit 4913ea7 into develop Nov 21, 2026
1 check 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