Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
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

Closed

Description

@ChrisLoer

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:

if (this.callback != null) {
throw new IllegalStateException("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).

/cc @friedbunny @julianrex @ivovandongen @1ec5

Activity

  1. self-assigned this
    on May 3, 2018
  2. added
    Core
    on May 3, 2018
  3. ChrisLoer commented on May 3, 2018

    @ChrisLoer
    ContributorAuthor

    The darwin wrapper does not currently enforce "one snapshot at a time", so you can get some wacky results.

    Err, that wasn't right:

    if ([self isLoading]) {
    [NSException raise:NSInternalInconsistencyException
    format:@"Already started this snapshotter."];
    }

    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).

  4. added
    Android
    on May 3, 2018
  5. ChrisLoer commented on May 3, 2018

    @ChrisLoer
    ContributorAuthor

    The Android wrapper enforces this

    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.

  6. ChrisLoer commented on May 3, 2018

    @ChrisLoer
    ContributorAuthor
  7. ChrisLoer commented on May 17, 2018

    @ChrisLoer
    ContributorAuthor

    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.
  8. added
    archived
    on Nov 15, 2018
  9. stale commented on Nov 24, 2018

    @stale

    This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

AndroidCorearchivedrefactor

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions