Repository navigation
Ignore flipped glyphs when placing labels for perf - #257
Conversation
|
Nice work @mourner! Looks great. One issue I see is that there will likely be an extra copy of the diff --git a/src/text/placement.cpp b/src/text/placement.cpp
index dbf7286..c0fe81e 100644
--- a/src/text/placement.cpp
+++ b/src/text/placement.cpp
@@ -72,14 +72,6 @@ struct GlyphInstance {
const float angle = 0.0f;
};
-struct GlyphsAndBoxes {
- explicit GlyphsAndBoxes(const PlacedGlyphs &glyphs, const GlyphBoxes &boxes)
- : glyphs(glyphs), boxes(boxes) {}
-
- const PlacedGlyphs glyphs;
- const GlyphBoxes boxes;
-};
-
typedef std::vector<GlyphInstance> GlyphInstances;
void getSegmentGlyphs(std::back_insert_iterator<GlyphInstances> glyphs,
@@ -153,10 +145,12 @@ void getSegmentGlyphs(std::back_insert_iterator<GlyphInstances> glyphs,
}
}
-GlyphsAndBoxes getGlyphs(Anchor &anchor, float advance, const Shaping &shaping,
- const IndexedFaces &faces, float fontScale,
- bool horizontal, const std::vector<Coordinate> &line,
- float maxAngleDelta, float rotate) {
+void getGlyphs( PlacedGlyphs &glyphs,
+ GlyphBoxes &boxes,
+ Anchor &anchor, float advance, const Shaping &shaping,
+ const IndexedFaces &faces, float fontScale,
+ bool horizontal, const std::vector<Coordinate> &line,
+ float maxAngleDelta, float rotate) {
// The total text advance is the width of this label.
// TODO: figure out correct ascender height.
@@ -170,9 +164,6 @@ GlyphsAndBoxes getGlyphs(Anchor &anchor, float advance, const Shaping &shaping,
// origin.x -= advance;
// }
- PlacedGlyphs glyphs;
- GlyphBoxes boxes;
-
const uint32_t buffer = 3;
for (const GlyphPlacement &placed : shaping) {
@@ -264,8 +255,6 @@ GlyphsAndBoxes getGlyphs(Anchor &anchor, float advance, const Shaping &shaping,
}
}
}
-
- return GlyphsAndBoxes{glyphs, boxes};
}
void Placement::addFeature(TextBucket& bucket,
@@ -303,14 +292,15 @@ void Placement::addFeature(TextBucket& bucket,
}
for (Anchor anchor : anchors) {
- GlyphsAndBoxes glyphsAndBoxes =
- getGlyphs(anchor, advance, shaping, faces, fontScale, horizontal,
+ PlacedGlyphs glyphs;
+ GlyphBoxes boxes;
+ getGlyphs(glyphs, boxes, anchor, advance, shaping, faces, fontScale, horizontal,
line, maxAngleDelta, rotate);
PlacementProperty place =
- collision.place(glyphsAndBoxes.boxes, anchor, anchor.scale, maxPlacementScale,
+ collision.place(boxes, anchor, anchor.scale, maxPlacementScale,
padding, horizontal, info.alwaysVisible);
if (place) {
- bucket.addGlyphs(glyphsAndBoxes.glyphs, place.zoom, place.rotationRange,
+ bucket.addGlyphs(glyphs, place.zoom, place.rotationRange,
zoom - zOffset);
}
} |
|
@springmeyer wow, thanks for a really helpful comment Dane — agreed, will do! |
|
Done! |
|
Looks good, please merge. @springmeyer I've mostly been counting on return value optimization being done, so there's a lot of code that returns "copies", which should get optimized away. Do you think it's worth it to change the code to the other style? |
Ignore flipped glyphs when placing labels for perf
I noticed the heavy reliance on RVO. I think it should be fine, but I worried about this case since I presume the members of the class will trigger copies even with RVO. Would be worth testing this assumption when things quiet down. /cc @artemp in case he knows more on this. |
Should make placement faster due to much less objects put into rtree. In llmr-js, it made about 25% parsing improvement for Outdoors (mapbox/mapbox-gl-js#385). My first ever C++ pull, please let me know if there any stylistic problems. :)