From 3823f2b002e59d13e4bd769477d41d4c00e26a2e Mon Sep 17 00:00:00 2001 From: Masashi Katsumata Date: Mon, 5 Oct 2026 16:09:43 -0700 Subject: [PATCH 1/3] Follow the core driver API the collectors are built on (#11) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Have states report their own changes instead of being read for them Dragging the street tree map was heavy on a Pixel 5a long after the tile rendering stopped being the reason. Frame stats put 270 to 380 ms of every janky frame between AnimationStart and PerformTraversalsStart, with the GPU at a 16 ms 90th percentile; simpleperf put three quarters of the main thread in androidx.collection.ScatterSet.contains, under advanceGlobalSnapshot, under a snapshotFlow's apply observer. That observer belonged to the collector. To find in-place changes it read every state's fingerprint inside one snapshotFlow, and Compose asks such an observer, on every snapshot commit anywhere in the app, whether any object it read is among the changed ones — one contains per object read. 144,183 markers of a dozen fields each is about 1.7 million probes, and a drag commits a snapshot every frame. The loop ran the wrong way round. Asking "of everything I read, did any of it change?" costs the size of the collection whether or not anything changed; being told "this one changed" costs one call per actual change, and during a drag markers do not change at all. So the states push: every mutable field goes through StateMutationSignal.notifying, which writes through to the same mutableStateOf — the field stays readable from a composition exactly as before — and reports the write. On a Pixel 5a, same 144k markers, same drag: janky frames 17.7% -> 1.4% 90th 350ms -> 21ms 99th 700ms -> 24ms slow UI thread 19 -> 2 which is where an empty map already was (0.2%, 16ms, 19ms). Quartering the markers had quartered the cost, so this was never about what was drawn. The collector keeps its own id-to-state map of who is reporting. Membership reaches `flow` through a debounce, so a state added and removed inside one window is not in that map when the removal arrives; clearing by id there found nothing and left the state reporting for the rest of the collector's life, which the removal test caught. Two things go with it. The FingerPrint type parameter, which existed only for the diff — fingerPrint() stays, several providers do their own diffing with it. And asFlow() on all six state types plus CollectAndUpdateEach, the per-state watcher this replaced twice over: nothing called either, and they are the shape that must not come back. The failure mode of the swap is silent — a setter that forgets to report leaves the renderer drawing the old value, with nothing logged and nothing thrown — so OverlayCollectorMutationTest states the contract: a write arrives, an equal write does not, repeats inside a window collapse to the latest, a removed state goes quiet, and two states changing together both arrive. * Record the state mutation signal and cancellable renderTile Follows android-sdk-core: ComponentState now exposes a StateMutationSignal instead of an asFlow() fingerprint stream — states report their own writes rather than being read for them — and TileProviderInterface gained a default renderTile(request, isCancelled). --- api/android-geojson-layer.api | 3 +- .../geojson/GeoJSONFeatureState.kt | 137 +++++++++--------- .../com/mapconductor/geojson/GeoJSONLayer.kt | 3 +- 3 files changed, 72 insertions(+), 71 deletions(-) diff --git a/api/android-geojson-layer.api b/api/android-geojson-layer.api index ec47498..58f435a 100644 --- a/api/android-geojson-layer.api +++ b/api/android-geojson-layer.api @@ -67,6 +67,7 @@ public final class com.mapconductor.geojson.GeoJSONFeatureState implements com.m public com.mapconductor.geojson.GeoJSONFeatureState(java.lang.String, com.mapconductor.geojson.GeoJSONGeometry, java.util.Map, java.lang.Integer, java.lang.Integer, java.lang.Float, java.lang.Float, boolean); public com.mapconductor.geojson.GeoJSONFeatureState(java.lang.String, com.mapconductor.geojson.GeoJSONGeometry, java.util.Map, java.lang.Integer, java.lang.Integer, java.lang.Float, java.lang.Float, boolean, int, kotlin.jvm.internal.DefaultConstructorMarker); public java.lang.String getId(); + public com.mapconductor.core.StateMutationSignal getMutations(); public final com.mapconductor.geojson.GeoJSONGeometry getGeometry(); public final void setGeometry(com.mapconductor.geojson.GeoJSONGeometry); public final java.util.Map getProperties(); @@ -82,7 +83,6 @@ public final class com.mapconductor.geojson.GeoJSONFeatureState implements com.m public final boolean getVisible(); public final void setVisible(boolean); public final com.mapconductor.geojson.GeoJSONFeatureFingerPrint fingerPrint(); - public final kotlinx.coroutines.flow.Flow asFlow(); } public final class com.mapconductor.geojson.GeoJSONFeatureState$Companion { } @@ -238,6 +238,7 @@ public final class com.mapconductor.geojson.GeoJSONTileRenderer implements com.m public byte[] renderTile(com.mapconductor.core.tileserver.TileRequest); public final com.mapconductor.geojson.GeoJSONTileRenderer$GeoJSONHitTestResult hitTest(double, double, java.lang.Double, java.lang.Double); public final com.mapconductor.geojson.GeoJSONFeature hitTestFeature(double, double, java.lang.Double, java.lang.Double); + public byte[] renderTile(com.mapconductor.core.tileserver.TileRequest, kotlin.jvm.functions.Function0); public com.mapconductor.geojson.GeoJSONTileRenderer(); } public final class com.mapconductor.geojson.GeoJSONTileRenderer$Companion { diff --git a/src/main/java/com/mapconductor/geojson/GeoJSONFeatureState.kt b/src/main/java/com/mapconductor/geojson/GeoJSONFeatureState.kt index 4e75d2b..00f7f70 100644 --- a/src/main/java/com/mapconductor/geojson/GeoJSONFeatureState.kt +++ b/src/main/java/com/mapconductor/geojson/GeoJSONFeatureState.kt @@ -1,68 +1,69 @@ -package com.mapconductor.geojson - -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.setValue -import androidx.compose.runtime.snapshotFlow -import com.mapconductor.core.ComponentState -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.distinctUntilChanged - -class GeoJSONFeatureState( - featureId: String? = null, - geometry: GeoJSONGeometry, - properties: Map = emptyMap(), - strokeColor: Int? = null, - fillColor: Int? = null, - strokeWidth: Float? = null, - pointRadius: Float? = null, - visible: Boolean = true, -) : ComponentState { - override val id: String = featureId ?: buildDefaultId(geometry, properties) - - var geometry by mutableStateOf(geometry) - var properties by mutableStateOf(properties) - var strokeColor by mutableStateOf(strokeColor) - var fillColor by mutableStateOf(fillColor) - var strokeWidth by mutableStateOf(strokeWidth) - var pointRadius by mutableStateOf(pointRadius) - var visible by mutableStateOf(visible) - - fun fingerPrint(): GeoJSONFeatureFingerPrint = - GeoJSONFeatureFingerPrint( - id = id.hashCode(), - geometry = geometry.hashCode(), - properties = properties.hashCode(), - style = styleHashCode(), - visible = visible.hashCode(), - ) - - fun asFlow(): Flow = snapshotFlow { fingerPrint() }.distinctUntilChanged() - - private fun styleHashCode(): Int { - var h = strokeColor.hashCode() - h = 31 * h + fillColor.hashCode() - h = 31 * h + strokeWidth.hashCode() - h = 31 * h + pointRadius.hashCode() - return h - } - - companion object { - private fun buildDefaultId( - geometry: GeoJSONGeometry, - properties: Map, - ): String { - var h = geometry.hashCode() - h = 31 * h + properties.hashCode() - return h.toString() - } - } -} - -data class GeoJSONFeatureFingerPrint( - val id: Int, - val geometry: Int, - val properties: Int, - val style: Int, - val visible: Int, -) +package com.mapconductor.geojson + +import androidx.compose.runtime.getValue +import androidx.compose.runtime.setValue +import com.mapconductor.core.ComponentState +import com.mapconductor.core.StateMutationSignal + +class GeoJSONFeatureState( + featureId: String? = null, + geometry: GeoJSONGeometry, + properties: Map = emptyMap(), + strokeColor: Int? = null, + fillColor: Int? = null, + strokeWidth: Float? = null, + pointRadius: Float? = null, + visible: Boolean = true, +) : ComponentState { + override val id: String = featureId ?: buildDefaultId(geometry, properties) + + /** + * Writes to the fields below are announced here rather than discovered by + * reading them all back. See [StateMutationSignal]. + */ + override val mutations = StateMutationSignal() + + var geometry by mutations.notifying(geometry) + var properties by mutations.notifying(properties) + var strokeColor by mutations.notifying(strokeColor) + var fillColor by mutations.notifying(fillColor) + var strokeWidth by mutations.notifying(strokeWidth) + var pointRadius by mutations.notifying(pointRadius) + var visible by mutations.notifying(visible) + + fun fingerPrint(): GeoJSONFeatureFingerPrint = + GeoJSONFeatureFingerPrint( + id = id.hashCode(), + geometry = geometry.hashCode(), + properties = properties.hashCode(), + style = styleHashCode(), + visible = visible.hashCode(), + ) + + private fun styleHashCode(): Int { + var h = strokeColor.hashCode() + h = 31 * h + fillColor.hashCode() + h = 31 * h + strokeWidth.hashCode() + h = 31 * h + pointRadius.hashCode() + return h + } + + companion object { + private fun buildDefaultId( + geometry: GeoJSONGeometry, + properties: Map, + ): String { + var h = geometry.hashCode() + h = 31 * h + properties.hashCode() + return h.toString() + } + } +} + +data class GeoJSONFeatureFingerPrint( + val id: Int, + val geometry: Int, + val properties: Int, + val style: Int, + val visible: Int, +) diff --git a/src/main/java/com/mapconductor/geojson/GeoJSONLayer.kt b/src/main/java/com/mapconductor/geojson/GeoJSONLayer.kt index cb9a6eb..0104cfa 100644 --- a/src/main/java/com/mapconductor/geojson/GeoJSONLayer.kt +++ b/src/main/java/com/mapconductor/geojson/GeoJSONLayer.kt @@ -31,8 +31,7 @@ fun MapViewScope.GeoJSONLayer( ) { val featureCollector = remember { - OverlayCollector( - fingerPrintOf = { it.fingerPrint() }, + OverlayCollector( updateDebounce = Settings.Default.composeEventDebounce, ) } From 722f100be7d8c1924e8a9a65ca6bb2738780671f Mon Sep 17 00:00:00 2001 From: Masashi Katsumata Date: Wed, 28 Oct 2026 13:47:14 -0700 Subject: [PATCH 2/3] Add .claude/settings.json --- .claude/settings.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .claude/settings.json diff --git a/.claude/settings.json b/.claude/settings.json new file mode 100644 index 0000000..671a084 --- /dev/null +++ b/.claude/settings.json @@ -0,0 +1,6 @@ +{ + "attribution": { + "commit": "", + "pr": "" + } +} From 740babd9587f3b6cf97e9289d31f270feaa1ce04 Mon Sep 17 00:00:00 2001 From: Masashi Katsumata Date: Fri, 13 Nov 2026 03:40:47 -0800 Subject: [PATCH 3/3] Release 1.4.0 --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 7a6ca24..495c16f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,6 +8,6 @@ minSdk=26 javaVersion=17 jvmTarget=17 -libraryVersion=1.3.1 -coreLibraryVersion=1.3.1 +libraryVersion=1.4.0 +coreLibraryVersion=1.4.0 android.generateSyncIssueWhenLibraryConstraintsAreEnabled=false