ebiten: remove vertex copying in DrawTriangles()
/ DrawTrianglesShader()
loop
#3103
Closed
11 tasks done
Labels
Milestone
Ebitengine Version
v2.8.0-alpha.9 (?) / latest master
Operating System
Go Version (
go version
)1.23.0
What steps will reproduce the problem?
This is just an issue tracking a small optimization for
Image.DrawTriangles()
andImage.DrawTrianglesShader()
. Internally, these functions loop through a slice of vertices and copy their contents to an internal vertex data slice before proceeding with rendering. This can be seen here:https://github.com/hajimehoshi/ebiten/blob/main/image.go#L721
Currently, this is done with
for i, v := range vertices
- by using this version of a for loop, the vertex data is copied intov
. This is an unnecessary step, since we're then just copying the data directly into the internal vertex slice.This should probably be replaced with
for i := range vertices
, after which we can just index the vertices slice to get the data.In my limited testing and profiling, adjusting the loop this makes the loop take about 13% less time. Timing the loop itself went from ~216µs to ~188µs per
DrawTrianglesShader()
call with a relatively large number of vertices (about 6000 triangles per call).What is the expected result?
N/A
What happens instead?
N/A
Anything else you feel useful to add?
N/A
The text was updated successfully, but these errors were encountered: