Rasterize to RGBA, then copy to NRGBA#6244
Conversation
andydotxyz
left a comment
There was a problem hiding this comment.
I agree this sounds worth it. Probably with a comment in the code to make sure folk don't accidentally remove the seemingly wasteful draw/copy process.
Contributing upstream is a nice idea too, a longer term fix perhaps - if there is an issue then leave that in the comment as well so we can find it later.
|
Probably makes sense to add a benchmark test to make it easier to verify (now and in the future) the performance improvements |
Absolutely. Just wanted to confirm it was worth moving forward before making a benchmark :) |
|
Ready for review. I have added a benchmark, fixed the snapshots, and added an explanatory comment so the copy doesn't get removed accidentally in the future. Here is the benchmark results on my machine: |
|
One thing I'd like to discuss: This change will break existing snapshot tests for user applications. I don't think there is a way to avoid this. How do we let users know that snapshot test breakage is expected once this lands? |
|
Would be interesting to run the benchmark for different sizes of output image as well, especially small sizes. 16x16, 32x32, 64x64, etc. The old approach could be more efficient for small images (or maybe not) |
This is for 16x16: Looks like it's still way faster, but not quite as fast as for 500x500 |
This is an interesting question @andydotxyz. Given that we've made changes before that necessitate replacing all the golden .pngs for tests, I think it's a non-issue and we don't promise that pixel perfect rendering remains the same across even patch versions? |
|
Yes that's about the size of it. In general in my tutorials etc I encourage using unit testing on behaviour not image capture. |
While trying to speed up fyne solitaire, I discovered that golang.org/x/image has a fast path for RGBA dst images, which results in much faster raster times compared to NRGBA. The difference is so great that even the extra overhead of copying an RGBA image to a new NRGBA image after the raster results in ~65% faster svg rendering speeds.
The downside is that there are numerous off-by-1 errors that cause all of the SVG snapshot tests to fail, as well as any snapshot tests that contain an SVG (There's a lot), though I do not see any difference visually between the snapshots. Still, I think it's worth considering, given how massive of a speed boost it gives.
Another option would be to contribute a fast path to golang.org/x/image for NRGBA, but I haven't looked into how feasible that is.
Checklist: