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

queryRenderedFeatures gets very slow with complex maps due to O(n^2) layerId lookup in loadMatchingFeature #4770

Open
tomhicks opened this issue Sep 27, 2024 · 1 comment
Labels
enhancement New feature or request PR is more than welcomed Extra attention is needed

Comments

@tomhicks
Copy link
Contributor

I know exactly how to fix this: we need to pass layers as a Set rather than a list and use .has instead of arrayIntersects and filterLayerIDs.indexOf(layerID).

The problem here is that this is likely to alter the signature of some parts of MapLibre that might be considered public. For instance, although this is accessed usually via map.queryRenderedFeatures there are other entry points such as via the Tile class.

How should I proceed in making a PR here? We could accept either and check if it's an Array or Set all the way down?

maplibre-gl-js version: 4.7

browser: All

Steps to Trigger Behavior

  1. Have a complex map with lots of layers (100s of layers are needed)
  2. Use query rendered features and look at the performance trace

Link to Demonstration

An immense amount of time being spent in loadMatchingFeatures
image

Expected Behavior

It shouldn't get quadratically slower as layers are added.

Actual Behavior

It gets quadratically slower as layers are added.

@HarelM
Copy link
Collaborator

HarelM commented Sep 27, 2024

Map is the relevant public API, tile is less interesting.
If you have a good solution you are welcome to open a PR.
We are also nearing version 5, so we might be able to introduce a breaking change.

@HarelM HarelM added enhancement New feature or request PR is more than welcomed Extra attention is needed labels Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request PR is more than welcomed Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants