internal/stroke, gpu: reuse slice when splitting cubics

When building GPU vertices from paths, we call stroke.SplitCubic once
per OpCubic. Before this change, each call to stroke.SplitCubic would
allocate a slice, which we would only use to iterate over.

This allocation can be easily avoided by reusing the slice. We can
conveniently store it in gpu.quadSplitter.

In a real application that renders hundreds of paths with tens of
rounded rectangles per path, this saved roughly 4500 allocations (or 1
MB worth) per frame.

Signed-off-by: Dominik Honnef <dominik@honnef.co>
This commit is contained in:
Dominik Honnef
2023-06-15 01:31:40 +02:00
committed by Elias Naur
parent 90e57c2b18
commit b183774063
3 changed files with 11 additions and 4 deletions
+3
View File
@@ -12,6 +12,9 @@ type quadSplitter struct {
bounds f32.Rectangle
contour uint32
d *drawOps
// scratch space used by calls to stroke.SplitCubic
scratch []stroke.QuadSegment
}
func encodeQuadTo(data []byte, meta uint32, from, ctrl, to f32.Point) {