Skip to content

internal: fix smallBuf allocation in the reader#546

Merged
oleg-jukovec merged 1 commit intomasterfrom
oleg-jukovec/gh-no-local-smallbuf
Mar 18, 2026
Merged

internal: fix smallBuf allocation in the reader#546
oleg-jukovec merged 1 commit intomasterfrom
oleg-jukovec/gh-no-local-smallbuf

Conversation

@oleg-jukovec
Copy link
Collaborator

@oleg-jukovec oleg-jukovec commented Mar 18, 2026

Move smallBuf variable declaration outside the reader loop to reduce memory allocations per request.

Benchmark results (BenchmarkSync_naive_with_custom_type_with_Release):

  • master: 4 allocs/op, 321 B/op
  • this fix: 3 allocs/op, 288 B/op

Add examples demonstrating custom Request implementation with the Response method. The examples show that custom requests must read all response data immediately since the io.Reader is only valid during the call.

@oleg-jukovec oleg-jukovec force-pushed the oleg-jukovec/gh-no-local-smallbuf branch from bf8cdb5 to d841832 Compare March 18, 2026 00:29
@oleg-jukovec oleg-jukovec changed the title api: move smallBuf allocation outside the reader loop internal: fix smallBuf allocation in the reader Mar 18, 2026
Move `smallBuf` variable declaration outside the reader loop to reduce
memory allocations per request.

Benchmark results (BenchmarkSync_naive_with_custom_type_with_Release):

- master:    4 allocs/op, 321 B/op
- this fix:  3 allocs/op, 288 B/op

Add examples demonstrating custom Request implementation with the
Response method. The examples show that custom requests must read all
response data immediately since the io.Reader is only valid during
the call.
@oleg-jukovec oleg-jukovec force-pushed the oleg-jukovec/gh-no-local-smallbuf branch from d841832 to 635572c Compare March 18, 2026 00:48
@oleg-jukovec oleg-jukovec merged commit 5c57097 into master Mar 18, 2026
27 checks passed
@oleg-jukovec oleg-jukovec deleted the oleg-jukovec/gh-no-local-smallbuf branch March 18, 2026 18:10
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.

2 participants