Skip to content

Respect property functions in queryRenderedFeatures - #4243

Merged
anandthakker merged 10 commits into
masterfrom
3604
Feb 9, 2017
Merged

anandthakker merged 10 commits into
masterfrom
3604

Conversation

@anandthakker

Copy link
Copy Markdown
Contributor

Approach:

  • Collect paintPropertyStatistics for data-driven paint properties while populating paint vertex arrays on the Worker side. (Specifically, store the max value for each such property.)
  • In FeatureIndex#query, use these max values when calculating how much additional padding to use when querying the grid index. As features are indexed by their source geometries (rather than their rendered geometries), this ensures that our grid query yields all potential hits for the user's query.
  • Then, when filtering candidates from 👆 to those actually matching the user's query, use layer.getPaintValue() to obtain the actual paint property values for each feature.

Closes #3604

Launch Checklist

  • briefly describe the changes in this PR
  • write tests for all new functionality
  • post benchmark scores
  • manually test the debug page

Benchmark

benchmark master 3c52ddb 3604 429686e
map-load 163 ms 115 ms
style-load 96 ms 98 ms
buffer 1,051 ms 1,044 ms
fps 60 fps 60 fps
frame-duration 5 ms, 0% > 16ms 4.9 ms, 0% > 16ms
query-point 0.88 ms 1.05 ms
query-box 57.66 ms 82.00 ms
geojson-setdata-small 7 ms 4 ms
geojson-setdata-large 158 ms 184 ms

The test was passing despite the bug, because the query point was dead
center on the circle.  Now, the test fails, but changing the property
function to a literal 20 makes the test pass.
FeatureIndex#query will use the _max_ paint property value for its first
pass (querying the grid), but should use the _actual_ property value for
its second pass (filtering the rendered features that actually intersect
the query).  Verifying by a second feature that passes the first test
but fails the second.
@anandthakker

Copy link
Copy Markdown
Contributor Author

The core strategy is working here, but note that both query benchmarks took a hit. Gonna do some profiling to see if we can recover a bit.

@anandthakker

anandthakker commented Feb 9, 2017 •

Copy link
Copy Markdown
Contributor Author

Ran benchmarks again after 2352e12:

benchmark master 80aa693 3604 2352e12
map-load 154 ms 98 ms
style-load 96 ms 96 ms
buffer 1,104 ms 1,109 ms
fps 60 fps 60 fps
frame-duration 4.4 ms, 0% > 16ms 4.4 ms, 0% > 16ms
query-point 0.88 ms 1.20 ms
query-box 69.58 ms 77.37 ms
geojson-setdata-small 7 ms 5 ms
geojson-setdata-large 171 ms 184 ms

Given the change from the previous benchmark run (query-point: +19% => +36%, query-box: +41% => +10%), it's hard to say what the true perf hit is here.

Based on profiling, I think we can attribute about 10% increase in queryRenderedFeatures time to the overhead of using getPaintValue() versus just accessing layer.paint[] -- i.e., 10% is basically the cost of correctness here. My gut feeling is that the rest is sample noise and that we probably won't do much better.

cc: @jfirebaugh @mourner

@jfirebaugh jfirebaugh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add query tests for data-driven line-gap-width and data-driven line-offset?

Comment thread src/data/array_group.js Outdated
if (ElementArrayType2) this.elementArray2 = new ElementArrayType2();

this.layerData = {};
this.paintPropertyStatistics = {};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather that creating another layer-id-keyed map, can we store the statistics as a property on this.layerData[layer.id]?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jfirebaugh yeah, sure -- I actually started down that route, and then bailed because doing so would bifurcate the contents of ArrayGroup#layerData and the corresponding BufferGroup#layerData, and thought that might be (slightly) worse. I don't have a strong opinion on this though, so deferring to you.

Comment thread src/data/bucket/symbol_bucket.js Outdated
}

getPaintPropertyStatistics() {
return util.extend({}, this.arrays.icon.paintPropertyStatistics, this.arrays.glyph.paintPropertyStatistics);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both of these are keyed by layer ID, so doesn't this overwrite icon statistics with glyph statistics?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops -- good catch, thanks.

16
],
"ignored": {
"native": "https://github.com/mapbox/mapbox-gl-native/issues/6518"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapbox/mapbox-gl-native#6518 is "Add support for identity function type" and is closed. Can you open a new parity issue and update this URL (and in the other test too)?

@anandthakker

Copy link
Copy Markdown
Contributor Author

@jfirebaugh back to you

@anandthakker
anandthakker merged commit 35d4d85 into master Feb 9, 2017
@anandthakker
anandthakker deleted the 3604 branch February 9, 2017 21:02
if (attribute.dimensions !== 1) continue;
paintPropertyStatistics[attribute.property] = {
max: -Infinity
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we anticipate adding other statistics in the near term?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants