Skip to content

perf(query): pre-size mergedList in merge()#9721

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

perf(query): pre-size mergedList in merge()#9721
shaunpatterson wants to merge 1 commit into
dgraph-io:mainfrom
shaunpatterson:perf/query-merge-presize

Conversation

@shaunpatterson
Copy link
Copy Markdown
Contributor

The @normalize merge appends exactly one node per (parent,child) pair, so the final length is len(parent)*len(child). Pre-sizing avoids grow-and-copy.

BenchmarkMergeNormalize (64×64): allocs/op 25→10 (-60%), time -24%.


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.

@shaunpatterson shaunpatterson requested a review from a team as a code owner May 28, 2026 18:19
The @normalize merge appends exactly one node per (parent,child) pair, so the
final length is len(parent)*len(child). Pre-sizing avoids grow-and-copy.

The capacity is capped at x.Config.LimitNormalizeNode: the loop bails out once
the node count exceeds that limit, so without the cap a large normalize query
that is going to be rejected would still trigger a huge (or integer-overflowing)
up-front allocation.

BenchmarkMergeNormalize (64x64): allocs/op 25 -> 10 (-60%), time -24%.
@shaunpatterson shaunpatterson force-pushed the perf/query-merge-presize branch from bc030e4 to e868b07 Compare May 28, 2026 18:34
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