-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] Reduce allocations for polyline generation #47837
Changes from 6 commits
1bc0c4d
ebfaabb
84d2e20
a92b757
aa280ec
cd60b9f
07eee60
761be29
4d9fe4e
720a0ee
615f8fd
71afaa0
da16afe
d9a0ab9
eaa07be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -128,9 +128,9 @@ StrokePathGeometry::JoinProc StrokePathGeometry::GetJoinProc(Join stroke_join) { | |
| PathBuilder::kArcApproximationMagic * alignment * | ||
| dir; | ||
|
|
||
| auto arc_points = CubicPathComponent(start_offset, start_handle, | ||
| middle_handle, middle) | ||
| .CreatePolyline(scale); | ||
| std::vector<Point> arc_points; | ||
| CubicPathComponent(start_offset, start_handle, middle_handle, middle) | ||
| .AppendPolylinePoints(scale, arc_points); | ||
|
|
||
| VS::PerVertexData vtx; | ||
| for (const auto& point : arc_points) { | ||
|
|
@@ -192,7 +192,9 @@ StrokePathGeometry::CapProc StrokePathGeometry::GetCapProc(Cap stroke_cap) { | |
| vtx_builder.AppendVertex(vtx); | ||
| vtx.position = position - orientation; | ||
| vtx_builder.AppendVertex(vtx); | ||
| for (const auto& point : arc.CreatePolyline(scale)) { | ||
| std::vector<Point> arc_points; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same deal. This shouldn't typically result in a large number of points. |
||
| arc.AppendPolylinePoints(scale, arc_points); | ||
| for (const auto& point : arc_points) { | ||
| vtx.position = position + point; | ||
| vtx_builder.AppendVertex(vtx); | ||
| vtx.position = position + (-point).Reflect(forward_normal); | ||
|
|
@@ -234,7 +236,9 @@ StrokePathGeometry::CreateSolidStrokeVertices( | |
| const StrokePathGeometry::CapProc& cap_proc, | ||
| Scalar scale) { | ||
| VertexBufferBuilder<VS::PerVertexData> vtx_builder; | ||
| auto polyline = path.CreatePolyline(scale); | ||
| std::vector<Point> point_buffer; | ||
| point_buffer.reserve(512); | ||
|
||
| auto polyline = path.CreatePolyline(scale, point_buffer); | ||
|
|
||
| VS::PerVertexData vtx; | ||
|
|
||
|
|
||
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.
Can the reserve size be calculated here?
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.
These are small and shouldn't result in lots of reallocation. I'd feel more comfortable having a benchmark showing this before trying to place a number in it.
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 ask because I'm turning on a linter for this in #47868. I don't think it will flag this though since it can't trivially know what the reserve size is.
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.
Reserving incorrect sizes can make things worse. If we don't know let's use the standard vec reallocation startegy