Repository navigation
Keep Marker, Polyline and Polygon state in one snapshot record - #55
Merged
Merged
Conversation
Each mutable field was its own mutableStateOf behind a NotifyingState: four objects per field, 7 to 13 fields per state. On the JVM a marker was 1,340 B, a polyline 942 B and a polygon 1,152 B before any points. CircleState already kept its fields in one record. The three now do the same: a private Values data class held in a single mutableStateOf (marker 293 B, polyline 261 B, polygon 269 B). A write compares only the field it writes, as before, and is serialized so two threads writing different fields both land. The marker's iconRevision moves into the record too. Street Trees (144,183 markers) on a Pixel 5a: app heap 334 MB -> 146 MB.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
MarkerState,PolylineStateandPolygonStateheld each mutable field in its ownmutableStateOfbehind aNotifyingState: four objects per field (NotifyingState,ParcelableSnapshotMutableState, itsStateStateRecord, anAtomicInt), and 7 to 13 fields per state.CircleStatealready kept its fields in one record.Per state on the JVM, points excluded:
Street Trees (144,183 markers) on a Pixel 5a, MapLibre, 60 s after opening:
dumpsys meminfoJava HeapWhat
Valuesdata class held in a singlemutableStateOf, asCircleStatedoes. The marker'siconRevision(bumped when a URL icon's image arrives) moves into the record instead of its ownmutableIntStateOf.synchronized(this). With one record a write is read-copy-write, and without the lock two threads writing different fields (an animation moving a marker while the app swaps its icon) could lose one of them. Per-field states could not.apiDumpadds the privateValuesclasses (80 lines, none removed), asCircleState$Valuesalready is in the baseline.Behaviour difference
A composition that reads any field of one of these states now recomposes when any field of it changes, as it already did for
CircleState. Nothing in android-sdk-compose writes to a state from inside the composition that reads it (Marker(...)builds a new state per recomposition), so this does not loop. TheiconRevisionKDoc is updated to match.Checked
:android-sdk-core:testDebugUnitTest: 449 pass:android-sdk-core:apiCheck: pass afterapiDumpiOS was measured as well (simulator, 424-488 B per state for all four types, the same
@Published-per-field shape) and needs no change.Independent of #54.