Skip to content

perf: eliminate per-iteration allocation in fillBufferSingleBitAllocated#378

Open
suyashkumar wants to merge 1 commit into
mainfrom
claude/agitated-bardeen-049ee2
Open

perf: eliminate per-iteration allocation in fillBufferSingleBitAllocated#378
suyashkumar wants to merge 1 commit into
mainfrom
claude/agitated-bardeen-049ee2

Conversation

@suyashkumar

@suyashkumar suyashkumar commented May 17, 2026

Copy link
Copy Markdown
Owner

Move the rawData buffer allocation outside the loop so a single []byte is reused across all iterations instead of allocating once per 8-pixel group. For a 512×512 1-bit image this reduces allocs from 32,770 to 3 per call and improves throughput by ~1.6× (379µs → 233µs).

Also adds BenchmarkFillBufferSingleBitAllocated to cover this path.

Metric Before After Delta
512×512 time 379 µs/op 233 µs/op −1.6× faster
512×512 allocs 32,770 allocs/op 3 allocs/op −99.99%
512×512 memory 36,912 B/op 4,145 B/op −88.8%
1024×1024 time 1,526 µs/op 933 µs/op −1.6× faster
1024×1024 allocs 131,074 allocs/op 3 allocs/op −99.99%
1024×1024 memory 135,216 B/op 4,145 B/op −96.9%

Move the rawData buffer allocation outside the loop so a single []byte
is reused across all iterations instead of allocating once per 8-pixel
group. For a 512×512 1-bit image this reduces allocs from 32,770 to 3
per call and improves throughput by ~1.6× (379µs → 233µs).

Also adds BenchmarkFillBufferSingleBitAllocated to cover this path,
which was previously untested by the existing benchmark suite.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant