Skip to content

perf(posting): avoid redundant proto.Clone in setMutationAfterCommit#9717

Open
shaunpatterson wants to merge 1 commit into
dgraph-io:mainfrom
shaunpatterson:perf/posting-commit-no-clone
Open

perf(posting): avoid redundant proto.Clone in setMutationAfterCommit#9717
shaunpatterson wants to merge 1 commit into
dgraph-io:mainfrom
shaunpatterson:perf/posting-commit-no-clone

Conversation

@shaunpatterson
Copy link
Copy Markdown
Contributor

When rebuilding committedEntries, copy the *pb.PostingList values by reference instead of proto.Clone. Per MutableLayer's documented invariant, committed entries are immutable once inserted and MutableLayer.clone() already shares the map by reference, so the deep clone was redundant. Only the map itself must be freshly allocated.

BenchmarkSetMutationAfterCommit: sec/op -79%, B/op -82%, allocs/op 15.26k→40 (-99.7%). Full posting unit suite passes.


Independent change; branched from 4b9b399d (no dependency on the other PRs in this set). Verified: package unit tests pass + Go benchmark (benchstat, p<0.01). Numbers are single-thread microbenchmarks; not yet run through the Docker integration suite.

When rebuilding committedEntries, copy the *pb.PostingList values by reference
instead of proto.Clone. Per MutableLayer's documented invariant, committed
entries are immutable once inserted and MutableLayer.clone() already shares the
map by reference, so the deep clone was redundant. Only the map itself must be
freshly allocated.

BenchmarkSetMutationAfterCommit (priorEntries 1..256):
  sec/op    825µs -> 174µs (-78.9%, p=0.002)
  B/op      1.65Mi -> 304Ki (-82.0%, p=0.002)
  allocs/op 15.26k -> 40 (-99.74%, p=0.002)
@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