Skip to content

perf(query): pool encoder scaffolding across requests#9719

Open
shaunpatterson wants to merge 1 commit into
dgraph-io:mainfrom
shaunpatterson:perf/query-encoder-pool
Open

perf(query): pool encoder scaffolding across requests#9719
shaunpatterson wants to merge 1 commit into
dgraph-io:mainfrom
shaunpatterson:perf/query-encoder-pool

Conversation

@shaunpatterson
Copy link
Copy Markdown
Contributor

Reuse the encoder struct + attrMap + idSlice via a sync.Pool, cleared by free() in toFastJSON's defer.

buf is deliberately not pooled and is allocated fresh per request: toFastJSON returns enc.buf.Bytes() (a slice aliasing buf's backing array) to its caller after the encoder is freed, so pooling buf would let a concurrent request overwrite an in-flight response.

BenchmarkEncoderLifecycle: allocs/op 10→4 (-60%), time -14%.


Independent change; branched from 4b9b399d. Verified: package unit tests pass + Go benchmark (benchstat, p<0.01). Single-thread microbenchmarks; not yet run through the Docker integration suite.

Reuse the encoder struct + attrMap + idSlice via a sync.Pool, cleared by free()
in toFastJSON's defer. buf is deliberately NOT pooled and is allocated fresh per
request: toFastJSON returns enc.buf.Bytes() (a slice aliasing buf's backing
array) to its caller after the encoder is freed, so pooling buf would let a
concurrent request overwrite an in-flight response.

BenchmarkEncoderLifecycle: allocs/op 10 -> 4 (-60%), time -14%.
@shaunpatterson shaunpatterson requested a review from a team as a code owner May 28, 2026 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant