-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Pre-filter sources for queryRenderFeatures #2877
Conversation
Nice! Let's fix the build. |
^ last commit should fix the build and adds a test of the new behavior |
} else { | ||
sourcesToQuery = this.sources; | ||
} | ||
for (var id in sourcesToQuery) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we could get by with a simpler implementation like this 👇 ?
for (var id in this.sources) {
if (!params.layers) continue;
if (params.layers.some(function(layerId) { return this._layers[layerId].source === id; }) continue;
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, 👍 for filtering the sources within the loop like you propose.
I'm a little bit wary of using array.some()
here rather than a plain for loop over params.layers
, only because this method could get called with a pretty high frequency, e.g., in a mousemove
. handler, where this might make a difference. (But I admit this is based on intuition, not quantitative evidence)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the impact of Array.some
or equivalent logic will ever be a bottleneck next to Source#queryRenderedFeatures
. If it becomes one, we will identify it in the profiler and look for optimizations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, fair enough 😄
@lucaswoj ^ simplified the logic -- I did it this way because the "no-loop-func" linter rule prohibited the particular form you suggested |
Given that we're dealing with sources, the difference between discussed forms will be negligible because there are typically only a very few sources on a particular map. However, in other situations like this where there are more objects to deal with (like layers), the original form with a simple |
If we can't do the |
This change aims to improve queryRenderedFeatures performance in cases where a
layers
parameter is present by only querying the sources referenced by the requested layers.This can lead to significant savings in some cases because (a) the first time a newly-loaded source tile is queried, it must parse the pbf data into a VectorTile, and (b) tiles for some sources may be reloaded quite often if, for instance,
setFilter
orsetData
are being used for "hover"-like interactivity. (See also #2874)