Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bypass the DOM rendering queue if map is idle #10567

Merged
merged 3 commits into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -2528,6 +2528,10 @@ class Map extends Camera {
this.painter.setBaseState();

this._renderTaskQueue.run(paintStartTimeStamp);
// The queue below may have tasks that need to be run but the queue won't always be ran: to
// avoid this, tasks need to be called directly instead of being added to the queue. See
// ui/popup.js or ui/marker.js for example. This won't be a performance issue as very few
// elements will be concerned by the rendering.
this._domRenderTaskQueue.run(paintStartTimeStamp);
// A task queue callback may have fired a user event which may have removed the map
if (this._removed) return;
Expand Down
13 changes: 11 additions & 2 deletions src/ui/marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,11 +507,20 @@ export default class Marker extends Evented {
this._pos = this._pos.round();
}

this._map._domRenderTaskQueue.add(() => {
const transformFn = () => {
if (this._element && this._pos && this._anchor) {
DOM.setTransform(this._element, `${anchorTranslate[this._anchor]} translate(${this._pos.x}px, ${this._pos.y}px) ${pitch} ${rotation}`);
}
});
};

// This condition means that the map is idle: the transformation needs to be manually
// applied as there won't be a triggered render. This shouldn't impact performance as the
// move shoud be limited to very few elements.
if (!this._map.isMoving() && this._map.loaded()) {
transformFn();
} else {
this._map._domRenderTaskQueue.add(transformFn);
}
}

/**
Expand Down
14 changes: 12 additions & 2 deletions src/ui/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,12 +572,22 @@ export default class Popup extends Evented {
}

const offsetedPos = pos.add(offset[anchor]).round();
this._map._domRenderTaskQueue.add(() => {

const transformFn = () => {
if (this._container && anchor) {
DOM.setTransform(this._container, `${anchorTranslate[anchor]} translate(${offsetedPos.x}px,${offsetedPos.y}px)`);
applyAnchorClass(this._container, anchor, 'popup');
}
});
};

// This condition means that the map is idle: the transformation needs to be manually
// applied as there won't be a triggered render. This shouldn't impact performance as the
// move shoud be limited to very few elements.
if (!this._map.isMoving() && this._map.loaded()) {
transformFn();
} else {
this._map._domRenderTaskQueue.add(transformFn);
}
}

_focusFirstElement() {
Expand Down