Skip to content

Commit

Permalink
Optimize shouldPausePlacement to short circuit when _forceFullPlaceme…
Browse files Browse the repository at this point in the history
…nt (maplibre#24)

* shouldPausePlacement short circuits when _forceFullPlacement

* Add generated changelog entries

Co-authored-by: svc-changelog <svc-changelog@palantir.com>
  • Loading branch information
2 people authored and GitHub Enterprise committed Mar 6, 2023
1 parent 9fa1191 commit ebab0f2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 11 additions & 0 deletions changelog/@unreleased/pr-24.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type: improvement
improvement:
description: |-
Optimize shouldPausePlacement to short circuit when _forceFullPlacement
Some profiles of Gaia show significant time spent in the following functions. Each iteration of these hot loops makes a call to `shouldPausePlacement`, which previously would need to get the current system time (probably ~50ns), even when `_forceFullPlacement` was true. We now short circuit to avoid the `Date.now()` when `_forceFullPlacement == true`.
* [continuePlacement](https://github.palantir.build/acme/maplibre-gl-js/blob/8b76c2bc8ff1ec8aa09b83b7f45ca03cb6fcc0e2/src/style/pauseable_placement.ts#L50)
* [placeLayerBucketPart](https://github.palantir.build/acme/maplibre-gl-js/blob/8b76c2bc8ff1ec8aa09b83b7f45ca03cb6fcc0e2/src/symbol/placement.ts#L414)
links:
- https://github.palantir.build/acme/maplibre-gl-js/pull/24
6 changes: 4 additions & 2 deletions src/style/pauseable_placement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ class PauseablePlacement {
const startTime = browser.now();

const shouldPausePlacement = () => {
const elapsedTime = browser.now() - startTime;
return this._forceFullPlacement ? false : elapsedTime > 2;
if (this._forceFullPlacement) {
return false;
}
return browser.now() - startTime > 2;
};

while (this._currentPlacementIndex >= 0) {
Expand Down

0 comments on commit ebab0f2

Please sign in to comment.