Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ebiten: remove vertex copying in DrawTriangles() / DrawTrianglesShader() loop #3103

Closed
11 tasks done
SolarLune opened this issue Sep 16, 2024 · 0 comments
Closed
11 tasks done

Comments

@SolarLune
Copy link
Contributor

SolarLune commented Sep 16, 2024

Ebitengine Version

v2.8.0-alpha.9 (?) / latest master

Operating System

  • Windows
  • macOS
  • Linux
  • FreeBSD
  • OpenBSD
  • Android
  • iOS
  • Nintendo Switch
  • PlayStation 5
  • Xbox
  • Web Browsers

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() and Image.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 into v. 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

@SolarLune SolarLune added the bug label Sep 16, 2024
SolarLune added a commit to SolarLune/ebiten that referenced this issue Sep 16, 2024
@hajimehoshi hajimehoshi added this to the v2.8.0 milestone Sep 16, 2024
@hajimehoshi hajimehoshi changed the title Performance: Remove vertex copying in DrawTriangles() / DrawTrianglesShader() loop ebiten: remove vertex copying in DrawTriangles() / DrawTrianglesShader() loop Sep 16, 2024
SolarLune added a commit to SolarLune/ebiten that referenced this issue Sep 16, 2024
SolarLune added a commit to SolarLune/ebiten that referenced this issue Sep 16, 2024
SolarLune added a commit to SolarLune/ebiten that referenced this issue Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants