Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

fix redoPlacement blocking main thread, fix #3727 #3731

Merged
merged 1 commit into from
Jan 29, 2016

Conversation

ansis
Copy link
Contributor

@ansis ansis commented Jan 28, 2016

fix #3727

If a workRequest exists, don't cancel it and start an new request. It's ok to just do nothing if the request exists because a new call to redoPlacement will be triggered after the existing request finishes.

This fixes a regression in #3543

@tmpsantos can you review?

@1ec5 1ec5 added the performance Speed, stability, CPU usage, memory usage, or power usage label Jan 28, 2016
// Don't start a new placement request when the current one hasn't completed yet, or when
// we are parsing buckets.
if (workRequest) return;

workRequest.reset();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that line, and two others removed in fa522e02fe8fe58382a82643f9e4884136c59b76

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ok to remove the other two because workRequest = will destruct/cancel the old one, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's safe to remove this one; if (workRequest) return; guarantees that reset() would be a no-op. For the other ones, there's a difference:

  • reset, create new: Ensures the current task is ended and the callback for it will not be called, then starts a new one.
  • create new, assign: The callback for the previous task could still be executed, which might put things into an unexpected state.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, thanks! I should've checked. changed.

@ansis ansis force-pushed the fix-redo-placement-blocking branch 2 times, most recently from fa522e0 to 53dda0f Compare January 28, 2016 21:35
@tmpsantos
Copy link
Contributor

👍

@tmpsantos
Copy link
Contributor

I had the impression that by doing this we could potentially make text placement non deterministic.

I.e. if you rotate from angle A to B fast enough, in some cases we could skip the last redoPlacement because there was already a task going on with outdated values. So different "A -> B" could end up with labels in different places.

My solution was in a situation like there is a task ongoing, queue the redoPlacement for the next main loop interaction.

@1ec5 1ec5 added this to the ios-v3.1.0 milestone Jan 29, 2016
@ansis
Copy link
Contributor Author

ansis commented Jan 29, 2016

If you're rotating fast enough it could skip some of the intermediate redoPlacement calls, but the last one should always be the same. Since the results of redoPlacement should not depend on previous placement, it should be deterministic.

Whenever the map is rotated redoPlacement is called here which updates the placement config the tile needs to eventually get to. After a tile is loaded or redoPlacement finishes, it is called again until the placement is calculated for the latest PlacementConfig.

If a workRequest exists, don't cancel it and start an new request. It's
ok to just do nothing if the request exists because a new call to
redoPlacement will be triggered after the existing request finishes.

this fixes a regression in e44db93
@ansis ansis force-pushed the fix-redo-placement-blocking branch from 53dda0f to 0439d00 Compare January 29, 2016 18:35
@ansis ansis merged commit 0439d00 into master Jan 29, 2016
@ansis ansis deleted the fix-redo-placement-blocking branch January 29, 2016 19:16
@ansis ansis removed the in progress label Jan 29, 2016
@tmpsantos
Copy link
Contributor

💯 thanks a lot for explaining,

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
performance Speed, stability, CPU usage, memory usage, or power usage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[core] Text placement might block the Map Thread
4 participants