perf(test): support reusable image buffer in test.Canvas.Capture() to reduce heap churn in test suites
Author: hazyhaarCreated Aug 24, 2026Updated Sep 6, 2026
Checklist
- I have searched the issue tracker for open issues that relate to the same feature, before opening a new one.
- This issue only relates to a single feature. I will open new issues for any other features.
Is your feature request related to a problem?
In fyne.io/fyne/v2/test, calling Canvas.Capture() allocates a new image.NewNRGBA on every invocation:
- For a standard 1280x800 headless window, each capture allocates ~4.10 MB of heap memory.
- In automated test suites executing continuous visual checks, frame telemetry, or regression loops (e.g. 100+ frames), this creates significant GC pressure (~410 MB allocated for 100 frames) and frequent GC pauses during testing.
Is it possible to construct a solution with the existing API?
Currently, test.Canvas.Capture() returns a freshly allocated image.Image without exposing an option to write into an existing or pooled buffer.
Describe the solution you'd like to see.
Add a non-breaking helper method or allow buffer reuse, for example:
- Adding
CaptureTo(dst *image.NRGBA)(orCaptureTo(dst draw.Image)) ontest.WindowlessCanvas/test.Canvasto allow test runners and harnesses to reuse pre-allocated framebuffers across frames. - Or utilizing an internal buffer pool (
sync.Pool) for software rendering passes where appropriate.
Benchmark comparison (1280x800 Canvas Capture):
- Current
c.Capture(): 4,101,144 B/op, 304 allocs/op (~5.13 ms/op). - Reusable buffer / zero-alloc path: 0 B/op, 0 allocs/op (~2.27 ms/op, ~2.2x speedup).
Source: fyne-io/fyne