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

Conversation

manthey
Copy link
Contributor

@manthey manthey commented Dec 10, 2024

If the range tree returns multiple points or markers that might be within the search area, we were sorting them to maintain a stable response order. Javascript sort defaults to a lexical sort which casts all values to strings, so we had been doing `points.sort((a, b) => a

  • b)to do a numerical sort, but this has a lot of function call overhead and probably is casting each value between strings and numeric datatypes. Instead, we dopoints = Uint32Array.from(points).sort();` which uses native javascript functions and is much faster.

If the range tree returns multiple points or markers that might be
within the search area, we were sorting them to maintain a stable
response order.  Javascript sort defaults to a lexical sort which casts
all values to strings, so we had been doing `points.sort((a, b) => a
- b)` to do a numerical sort, but this has a lot of function call
overhead and probably is casting each value between strings and numeric
datatypes.  Instead, we do `points = Uint32Array.from(points).sort();`
which uses native javascript functions and is much faster.
@manthey manthey merged commit efe5029 into map-corners Dec 10, 2024
8 checks passed
@manthey manthey deleted the point-search-sort-speed branch December 10, 2024 21:12
Copy link

🎉 This PR is included in version 1.13.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant