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

perf: Speed up hit tests for points and markers #1355

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 11 additions & 7 deletions src/markerFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ var markerFeature = function (arg) {
// Find markers inside the bounding box
idx = m_rangeTree.range(min.x, min.y, max.x, max.y);

idx.sort((a, b) => a - b);
idx = Uint32Array.from(idx).sort();
// Filter by circular region
idx.forEach(function (i) {
var d = data[i],
Expand Down Expand Up @@ -353,16 +353,20 @@ var markerFeature = function (arg) {
};
// Find markers inside the bounding box. Only these could be in the polygon
idx = m_rangeTree.range(min.x, min.y, max.x, max.y);
// sort by index
idx.sort((a, b) => a - b);
/* sort by index. This had been
* idx.sort((a, b) => a - b);
* but this requires continual casting from int to str and back, so using
* a Uint32Array is faster, though potentially limits the maximum number of
* markers. */
idx = Uint32Array.from(idx).sort();
// filter markers within the polygon
idx.forEach(function (i) {
var d = data[i];
let p = m_this.position()(d, i);
let rad = radius(data[i], i),
swz = scaleWithZoom(data[i], i);
const so = strokeOffset(data[i], i),
s = swz ? strokeWidth(data[i], i) : 0;
let rad = radius(d, i),
swz = scaleWithZoom(d, i);
const so = strokeOffset(d, i),
s = swz ? strokeWidth(d, i) : 0;
let ris = radiusIncludesStroke(d, i);
ris = ris === undefined ? true : ris;
const rwos = ris ? rad + s * (so - 1) / 2 : rad; // radius without stroke
Expand Down
4 changes: 2 additions & 2 deletions src/pointFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ var pointFeature = function (arg) {
// Find points inside the bounding box
idx = m_rangeTree.range(min.x, min.y, max.x, max.y);

idx.sort((a, b) => a - b);
idx = Uint32Array.from(idx).sort();
// Filter by circular region
idx.forEach(function (i) {
var d = data[i],
Expand Down Expand Up @@ -434,7 +434,7 @@ var pointFeature = function (arg) {
// Find points inside the bounding box. Only these could be in the polygon
idx = m_rangeTree.range(min.x, min.y, max.x, max.y);
// sort by index
idx.sort((a, b) => a - b);
idx = Uint32Array.from(idx).sort();
// filter points within the polygon
idx.forEach(function (i) {
var d = data[i],
Expand Down
Loading