Skip to content

perf(algo): pre-size heap in MergeSortedPacked#9714

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

perf(algo): pre-size heap in MergeSortedPacked#9714
shaunpatterson wants to merge 1 commit into
dgraph-io:mainfrom
shaunpatterson:perf/algo-packed-heap

Conversation

@shaunpatterson
Copy link
Copy Markdown
Contributor

Build the heap slice and call heap.Init (O(n)) instead of n×heap.Push, which boxes each elem into an interface{} (one heap alloc per input list).

BenchmarkMergeSortedPacked (1000 lists × 100 uids): allocs/op 104.1k→103.0k (-0.97%), B/op -0.58%.


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, which
boxes each elem into an interface{} (one heap alloc per input list).

BenchmarkMergeSortedPacked (1000 lists × 100 uids):
  allocs/op 104.1k -> 103.0k (-0.97%, p=0.002)
  B/op      21.34Mi -> 21.22Mi (-0.58%, 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