Skip to content

perf(algo): pre-size heap in internalMergeSortWithBuffer#9715

Open
shaunpatterson wants to merge 1 commit into
dgraph-io:mainfrom
shaunpatterson:perf/algo-uidlist-heap
Open

perf(algo): pre-size heap in internalMergeSortWithBuffer#9715
shaunpatterson wants to merge 1 commit into
dgraph-io:mainfrom
shaunpatterson:perf/algo-uidlist-heap

Conversation

@shaunpatterson
Copy link
Copy Markdown
Contributor

Build the heap slice and call heap.Init (O(n)) instead of n×heap.Push (per-element interface boxing).

BenchmarkMergeSorted/MergeSorted (10000 lists × 100 uids): allocs/op 20.02k→10.01k (-50%), B/op 11.46Mi→8.86Mi (-22.7%).


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.

Build the heap slice and call heap.Init (O(n)) instead of n×heap.Push
(per-element interface boxing).

BenchmarkMergeSorted/MergeSorted (10000 lists × 100 uids):
  allocs/op 20.02k -> 10.01k (-50.03%, p=0.002)
  B/op      11.46Mi -> 8.86Mi (-22.70%, 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