-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[core, ios] Improve performance of queryRenderedFeatures by reducing # of temp GeometryCollection #15183
Conversation
35bd951
to
bd77689
Compare
@tobrun can you take a look at this and see what changes are needed for Android. |
bd77689
to
5568810
Compare
|
||
if (offset == 0) return nullptr; | ||
|
||
std::unique_ptr<GeometryCollection> newRings = std::make_unique<GeometryCollection>(); |
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.
After some checks I came to conclusion that we could keep the old semantics with the optional
return type.
The problem was caused by implicit copy of the local variable on return, that can be fixed just with adding std::move()
call (RVO is failing here as local and return types are different).
optional<GeometryCollection> offsetLine() {
GeometryCollection newRings;
return newRings; // Copy here!
}
optional<GeometryCollection> offsetLine() {
GeometryCollection newRings;
return std::move(newRings); // No copy :)
}
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.
Gotcha - will test out.
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.
return std::move(newRings);
will prevent copy elision, I think we even have clang check for that.
Another option is to return optional<GeometryCollection>(std::move(newRings));
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.
hm, another issue could be that we have two return statements that could prevent RVO.
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.
return std::move(newRings); will prevent copy elision
in this case we're creating an instance of another type: optional<GeometryCollection>
. Returning rvalue triggers converting move constructor; returning lvalue triggers converting copy constructor.
@pozdnyakov can you help with the node changes? I started to try to understand what needs to be changed but very quickly hit a road block. Would the change back to |
afaik none at the moment |
The proposed change had slightly affected logic in |
4f5dac6
to
a534dd3
Compare
Just forced pushed, which overwrites @pozdnyakov's 4f5dac6 - running through Instruments shows that using Unfortunately the low average we were seeing earlier was due to the bug mentioned above - not making enough calls :( |
New low average is around 75ms (Both Release and RelWithDebInfo) - perhaps due to switch to |
31bec80
to
a3f7bfd
Compare
Rebased. |
Optional: could we squash some commits? |
@@ -112,8 +112,6 @@ static Feature::geometry_type convertGeometry(const GeometryTileFeature& geometr | |||
); | |||
}; | |||
|
|||
GeometryCollection geometries = geometryTileFeature.getGeometries(); |
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.
@julianrex @pozdnyakov was there a need to pass const GeometryCollection& geometries
all the way here when we already have constref to geometryTileFeature?
I think the problem was on line 115 where we made copy. Should have been:
const GeometryCollection& geometries = geometryTileFeature.getGeometries();
|
||
if (offset == 0) return nullptr; | ||
|
||
std::unique_ptr<GeometryCollection> newRings = std::make_unique<GeometryCollection>(); |
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.
return std::move(newRings);
will prevent copy elision, I think we even have clang check for that.
Another option is to return optional<GeometryCollection>(std::move(newRings));
@@ -8,6 +8,9 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT | |||
|
|||
* Fixed flickering on style change for the same tile set ([#15127](https://github.com/mapbox/mapbox-gl-native/pull/15127)) | |||
|
|||
### Other changes | |||
|
|||
* Improved feature querying performance (focussed on roads). ([#15183](https://github.com/mapbox/mapbox-gl-native/pull/15183)) |
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.
focused? 😄 I've never used focussed.
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.
UK English ;)
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.
If even the Europeans are against you... 😅
In any case, this also struck me as wrong. I think we should stick with ‘merican English, given our audience/company/etc.
Alternatively:
* Improved feature querying performance (focussed on roads). ([#15183](https://github.com/mapbox/mapbox-gl-native/pull/15183)) | |
* Improved feature querying performance of road features. ([#15183](https://github.com/mapbox/mapbox-gl-native/pull/15183)) |
@@ -265,13 +268,14 @@ bool RenderLineLayer::queryIntersectsFeature( | |||
.evaluate(feature, zoom, style::LineOffset::defaultValue()) * pixelsToTileUnits; | |||
|
|||
// Apply offset to geometry | |||
auto offsetGeometry = offsetLine(feature.getGeometries(), offset); | |||
auto offsetGeometry = offsetLine(geometries, offset); |
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.
const auto& offsetGeometry = offsetLine(geometries, offset);
Chatting with @alexshalamov - we're going to continue investigating this. |
@@ -8,6 +8,9 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT | |||
|
|||
* Fixed flickering on style change for the same tile set ([#15127](https://github.com/mapbox/mapbox-gl-native/pull/15127)) | |||
|
|||
### Other changes | |||
|
|||
* Improved feature querying performance (focussed on roads). ([#15183](https://github.com/mapbox/mapbox-gl-native/pull/15183)) |
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.
If even the Europeans are against you... 😅
In any case, this also struck me as wrong. I think we should stick with ‘merican English, given our audience/company/etc.
Alternatively:
* Improved feature querying performance (focussed on roads). ([#15183](https://github.com/mapbox/mapbox-gl-native/pull/15183)) | |
* Improved feature querying performance of road features. ([#15183](https://github.com/mapbox/mapbox-gl-native/pull/15183)) |
@@ -17,6 +17,8 @@ | |||
#import "../src/MGLMapView_Experimental.h" | |||
|
|||
#import <objc/runtime.h> | |||
#import <os/log.h> | |||
#import <os/signpost.h> |
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.
iosapp is larded down and we’ve been trying to trim it back — since this logging functionality could presumably be useful in other/future view controllers, can we move this stuff out into a separate file?
@julianrex @pozdnyakov pushed some experiments to https://github.com/mapbox/mapbox-gl-native/compare/alexshalamov_wip_qrf Not sure why 'unique_ptr' version is faster than construction / elision of geometrycollection on stack. |
Summarizing chat with @alexshalamov & @pozdnyakov: we are going to split this PR into 2 new ones:
@friedbunny I will address your comments in the new PR! |
This PR aims to improve performance of
queryRenderedFeatures
by reducing the number of temporaryGeometryCollection
that are allocated.getGeometries()
is now called once, rather than 3 times; it is passed in to subsequent functionsoffsetLine(...)
now returns astd::unique_ptr
- beforehand the copy-constructor & destructor were being called...a lot. (This is the main improvement).iosapp
has been updated with a menu entry so that we can test these improvements (and future improvements).Note - this does NOT have @pozdnyakov's suggestion of using
mbgl::Immutable
- I started, but I'd need to pair on this - perhaps we can do this as a follow-on PR?