Repository navigation
fix(android): apply ShapeSource data once, off the main thread - #4440
Merged
Merged
Conversation
Every shape was applied twice, through setStyleSourceProperty on the main thread and GeoJsonSource.data() on a worker. shape and url now go through setStyleGeoJSONSourceData once, on a serial worker of our own, so later work on the source can keep its order after them.
This branch was previously deployed
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.
Description
Fixes Android applying each
ShapeSourceshapetwice:setShapecalled bothsetStyleSourcePropertyon the main thread andGeoJsonSource.data(), which posts to the SDK's worker thread. Neither the data nor its order was under our control, and a later change to the source could be overwritten by the worker. #4439 needs that ordering.shapeandurlnow go throughsetStyleGeoJSONSourceDataonce, on one serial worker of ours. That includes the initial data inaddToMap, whichmakeSourceno longer passes to the builder. The SDK's GeoJSON calls have no main thread check, and its own worker makes the same one.Measured with 50k points on release builds on emulator-5554, 12 updates spaced 12 s apart so they never overlap, comparing clean
mainand clean fix builds, with the reproducer below:main, 25.0 s with the fix. The SDK's tile worker threads go from 37.3 s to 16.0 s, which is where the second apply shows.setShape: up to 117 ms to under 2 ms, because passing the 5 MB string to the SDK left the main thread. At mount and style reloadaddToMapstays the same asmain, 2-22 ms.CPU is noisy on this shared host. Across all runs
mainwas 48-54 s and the fix 23-86 s, and the 85.9 s run overlapped an Xcode build. The two quietest fix runs were 23.1 s and 25.0 s, so compare those. Applying on the main thread instead was also tried and rejected: it matched on CPU but took 33-200 ms of main thread at every mount and reload.Live
shapechange, style reload, liveurlchange, andexistingsources with and without ashapepass on both builds.Checklist
CONTRIBUTING.mdyarn generatein the root folder/exampleapp./example)Android only, no iOS code changes. No sample, as this is a fix.
Screenshot OR Video
Not a visual change.
Component to reproduce the issue you're fixing
Run Measure and Checks on
mainand on this branch. CPU was read from/proc/<pid>/statbetween theMARKlog lines.Reproducer