Skip to content

Cut per-shape bookkeeping in the collector and tile index - #54

Merged
wf9a5m75 merged 1 commit into
developfrom
perf/circle-bookkeeping
Nov 21, 2026
Merged

wf9a5m75 merged 1 commit into
developfrom
perf/circle-bookkeeping

Conversation

@wf9a5m75

Copy link
Copy Markdown
Contributor

Why

The US antenna example (723,800 circles) on a Pixel 5a kept the Java heap a few percent under the 512 MB largeHeap limit. A heap dump showed about 500 B per circle, of which roughly 130 B was SDK bookkeeping that exists only to find a state by id.

What

  • ShapeTileSet.indexById: HashMap<String, Int> → androidx.collection.ObjectIntMap<String>. No HashMap$Node or boxed Integer per shape. The map is still never changed after it is assigned (remove builds a new one, as before), so the sets ids() returns keep their snapshot semantics.
  • OverlayCollector.listening removed: it duplicated the flow map. The collector now looks states up in the map it last published plus pendingAdds (now id -> state, holding only direct adds still inside the debounce). onMutated drops a write from a state that is in neither the current map nor the pending adds, so a listener left behind by a missed membership change cannot deliver stale values.
  • One listener per collector: StateMutationSignal.listen(listener, state) with an internal StateMutationListener. The collector itself is the listener, instead of one closure per state. The lambda listen overload stays for tests.

No public API change (apiCheck passes; the new interface is @InternalMapConductorApi).

Measured (Pixel 5a, example-app debug, antenna page, MapLibre)

Heap dump, app heap, shallow:

develop this branch
total 455.3 MB 385.4 MB
java.util.HashMap$Node 794,717 70,884
java.lang.Integer 1,451,794 727,959
ConcurrentHashMap$Node 727,762 (gone)
OverlayCollector$$ExternalSyntheticLambda0 723,800 (gone)

dumpsys meminfo Java Heap, same script for both builds (open the page, then toggle T-Mobile, Verizon and Alaska three times):

develop this branch
~40 s after opening 416 MB 356 MB
after the toggles 357 MB 298 MB
peak sample 659 MB 508 MB
Clamp target GC heap log lines 10 1

No crash or OOM with either build during the run.

Checked

  • :android-sdk-core:testDebugUnitTest: 448 pass, including OverlayCollectorMutationTest
  • :android-sdk-core:apiCheck: pass
  • On device: all 723,800 circles draw; carrier toggles and the Alaska remount work; tapping a tiled circle opens its info bubble.

With the 723,800-circle antenna page on a Pixel 5a the Java heap sat a
few percent under the 512 MB largeHeap limit. Three structures held one
or more objects per circle only to find it again by id:

- ShapeTileSet.indexById was a HashMap<String, Int>: a node and a boxed
  Int per shape, plus a 2M-slot table. It is now an ObjectIntMap, still
  replaced rather than changed once assigned.
- OverlayCollector kept `listening`, a ConcurrentHashMap of every state
  it listens to, duplicating the flow map. It now finds them in the
  published map and the pending direct adds, and drops a write from a
  state that is no longer a member.
- Each state got its own closure as listener. The collector is now the
  one listener for all its states (StateMutationListener).
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