-
Notifications
You must be signed in to change notification settings - Fork 810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MergeIterator: allocate less memory at first #4341
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,8 +31,8 @@ func newMergeIterator(cs []GenericChunk) *mergeIterator { | |
c := &mergeIterator{ | ||
its: its, | ||
h: make(iteratorHeap, 0, len(its)), | ||
batches: make(batchStream, 0, len(its)*2*promchunk.BatchSize), | ||
batchesBuf: make(batchStream, len(its)*2*promchunk.BatchSize), | ||
batches: make(batchStream, 0, len(its)), | ||
batchesBuf: make(batchStream, len(its)), | ||
} | ||
|
||
for _, iter := range c.its { | ||
|
@@ -112,8 +112,7 @@ func (c *mergeIterator) buildNextBatch(size int) bool { | |
for len(c.h) > 0 && (len(c.batches) == 0 || c.nextBatchEndTime() >= c.h[0].AtTime()) { | ||
c.nextBatchBuf[0] = c.h[0].Batch() | ||
c.batchesBuf = mergeStreams(c.batches, c.nextBatchBuf[:], c.batchesBuf, size) | ||
copy(c.batches[:len(c.batchesBuf)], c.batchesBuf) | ||
c.batches = c.batches[:len(c.batchesBuf)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a no-op, right? Did it impact performance? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My guess about this change (but Bryan can confirm or negate), is that we had to do this change because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes the |
||
c.batches = append(c.batches[:0], c.batchesBuf...) | ||
|
||
if c.h[0].Next(size) { | ||
heap.Fix(&c.h, 0) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't recall exactly why the pre-allocation was so big - wondering if you know why?
I can't think of a reason why this would affect correctness either, and the perf results speak for themselves...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the correctness perspective, this change should be fine.
batchesBuf
looks to be written only bymergeStreams()
which extends the slice if required.