You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
MapSnapshotter can modify options of in-progress snapshot #11825
If you use any of the setters on a MapSnapshotter while it's in the middle of a snapshot, you will have some timing-dependent subset of those mutations applied to the snapshot you were taking This doesn't seem like a desirable interface -- right now the caller is essentially responsible for not mutating anything until the in progress snapshot completes.
Foreground
Background
snapshotter.snapshot(initial options, callback)
map.renderStill -> start tile fetching
snapshotter.setSize(newSize)
map.setSize(newSize)
tiles finish loading, map renders with newSize
The Android wrapper enforces this, although in a way that might make it easy to generate an unexpected exception:
thrownewIllegalStateException("Snapshotter was already started");
}
The darwin wrapper does not currently enforce "one snapshot at a time", so you can get some wacky results.
We could get rid of the mutation methods and just have snapshot take a fixed set of options as an argument, so that multiple snapshots could be queued and each ran against its original options. But given that Android is already working on the assumption that multiple snapshots can't be queued, maybe we should just hard-wire MapSnapshotter to only run once? The idea would be to make the wrappers responsible for implementing queuing/cancellation logic (or not, if they wanted they could make it so that many snapshotters run in parallel).
So the two wrappers are both enforcing "one snapshot at a time". I think this means this should be a pure under-the-hood refactoring: since the callers already expect the snapshotter to have a run-once interface, we should update it to match (and make it a little harder to shoot ourselves in the foot later).
I'm 0 for 2 on correctly reading the wrapper code! Android enforces that you can only run one snapshot at a time, but it does not prevent you from modifying options (using e.g. setSize) while a snapshot is in flight.
I think a good approach to fixing this is still to make the core snapshotter run-once -- we could maintain the same Android interface by making the wrapper maintain its own "current state" that mutates in response to setSize etc., and whenever you started a snapshot it would create the core snapshotter using those fixed options.
That would be similar to the approach currently used on iOS (setOptions creates a new core snapshotter object), although the current approach needs fixing: #11827.
I got a chance to talk with @ivovandongen about this, our conclusion was roughly:
We want to keep MapSnapshotter re-usable because of the overhead of creating map/style/renderer objects.
The core behavior should be that a snapshot runs to completion with a single set of options before any further work happens.
On Android, since we have to continue supporting an API that allows modifying options "in flight", we should maintain a queue of option-mutating requests (either in the wrapper or in core), and only apply them when we're starting a new snapshot.
On iOS, the current setOptions behavior re-sets the core MapSnapshotter object, which prevents us from getting any meaningful resource/performance benefit out of re-using MGLMapSnapshotter. We should change this to re-use the core snapshotter, just queuing a request with new options.
In the end, Android and iOS should have the same public APIs they do today, but (1) there shouldn't be any limitations on queueing multiple snapshots at a time, and (2) mutations to the platform-specific snapshotter only affect future snapshots.
The cancel method should cancel however many outstanding snapshots there might be -- I think the current implementation, which tears down the core snapshotter entirely, should be reasonable. As it stands, all resources are discarded and all network requests should be stopped. We might try a more lightweight version that just clears the tile pyramid (to reduce memory overhead and abort network requests) but doesn't require a full restart of the background renderer.
Activity
ChrisLoer commentedon May 3, 2018
Err, that wasn't right:
mapbox-gl-native/platform/darwin/src/MGLMapSnapshotter.mm
Lines 114 to 117 in 60ac08a
So the two wrappers are both enforcing "one snapshot at a time". I think this means this should be a pure under-the-hood refactoring: since the callers already expect the snapshotter to have a run-once interface, we should update it to match (and make it a little harder to shoot ourselves in the foot later).
ChrisLoer commentedon May 3, 2018
I'm 0 for 2 on correctly reading the wrapper code! Android enforces that you can only run one snapshot at a time, but it does not prevent you from modifying options (using e.g.
setSize) while a snapshot is in flight.I think a good approach to fixing this is still to make the core snapshotter run-once -- we could maintain the same Android interface by making the wrapper maintain its own "current state" that mutates in response to
setSizeetc., and whenever you started a snapshot it would create the core snapshotter using those fixed options.That would be similar to the approach currently used on iOS (
setOptionscreates a new core snapshotter object), although the current approach needs fixing: #11827.ChrisLoer commentedon May 3, 2018
cc @tobrun
[android, docs] Clean up MapSnapshotter javadoc.
ChrisLoer commentedon May 17, 2018
I got a chance to talk with @ivovandongen about this, our conclusion was roughly:
MapSnapshotterre-usable because of the overhead of creating map/style/renderer objects.setOptionsbehavior re-sets the coreMapSnapshotterobject, which prevents us from getting any meaningful resource/performance benefit out of re-usingMGLMapSnapshotter. We should change this to re-use the core snapshotter, just queuing a request with new options.cancelmethod should cancel however many outstanding snapshots there might be -- I think the current implementation, which tears down the core snapshotter entirely, should be reasonable. As it stands, all resources are discarded and all network requests should be stopped. We might try a more lightweight version that just clears the tile pyramid (to reduce memory overhead and abort network requests) but doesn't require a full restart of the background renderer.[android, docs] Clean up MapSnapshotter javadoc.
[android, docs] Clean up MapSnapshotter javadoc.
stale commentedon Nov 24, 2018
This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.