interval/generic: avoid letting argument to FirstOverlap escape to heap#45423
Merged
craig[bot] merged 2 commits intocockroachdb:masterfrom Feb 26, 2020
Merged
interval/generic: avoid letting argument to FirstOverlap escape to heap#45423craig[bot] merged 2 commits intocockroachdb:masterfrom
craig[bot] merged 2 commits intocockroachdb:masterfrom
Conversation
This was hiding the fact that FirstOverlap caused its argument to escape to the heap, forcing an allocation for some callers. The benchmarks now capture this: ``` name time/op BTreeIterFirstOverlap/count=16-16 400ns ± 1% BTreeIterFirstOverlap/count=128-16 661ns ± 0% BTreeIterFirstOverlap/count=1024-16 1.15µs ± 2% BTreeIterFirstOverlap/count=8192-16 1.84µs ± 2% BTreeIterFirstOverlap/count=65536-16 2.62µs ± 2% BTreeIterNextOverlap-16 11.1ns ± 2% BTreeIterOverlapScan-16 34.2µs ± 1% name alloc/op BTreeIterFirstOverlap/count=16-16 96.0B ± 0% BTreeIterFirstOverlap/count=128-16 96.0B ± 0% BTreeIterFirstOverlap/count=1024-16 96.0B ± 0% BTreeIterFirstOverlap/count=8192-16 96.0B ± 0% BTreeIterFirstOverlap/count=65536-16 96.0B ± 0% BTreeIterNextOverlap-16 0.00B BTreeIterOverlapScan-16 144B ± 0% name allocs/op BTreeIterFirstOverlap/count=16-16 1.00 ± 0% BTreeIterFirstOverlap/count=128-16 1.00 ± 0% BTreeIterFirstOverlap/count=1024-16 1.00 ± 0% BTreeIterFirstOverlap/count=8192-16 1.00 ± 0% BTreeIterFirstOverlap/count=65536-16 1.00 ± 0% BTreeIterNextOverlap-16 0.00 BTreeIterOverlapScan-16 6.40 ± 9% ```
Related to cockroachdb#45276. Prior to this change, the argument provided to `iterator.FirstOverlap` was stored in the iterator. This caused the argument to escape to the heap (if the parameterized type was a pointer) and would force an allocation if the argument was not already on the heap. This was not the intention and was causing issues in cockroachdb#45276. This commit fixes the issue by no longer storing the argument in the iterator's `overlapScan` object. This allows escape analysis to determine that the argument does not escape, like it was already doing for `iterator.SeekGE` and `iterator.SeekLT`. ``` name old time/op new time/op delta BTreeIterFirstOverlap/count=16-16 400ns ± 1% 325ns ± 5% -18.75% (p=0.008 n=5+5) BTreeIterFirstOverlap/count=128-16 661ns ± 0% 581ns ± 1% -12.02% (p=0.008 n=5+5) BTreeIterFirstOverlap/count=1024-16 1.15µs ± 2% 1.07µs ± 2% -6.76% (p=0.008 n=5+5) BTreeIterFirstOverlap/count=8192-16 1.84µs ± 2% 1.76µs ± 2% -4.38% (p=0.016 n=5+5) BTreeIterFirstOverlap/count=65536-16 2.62µs ± 2% 2.52µs ± 1% -4.07% (p=0.008 n=5+5) BTreeIterNextOverlap-16 11.1ns ± 2% 10.7ns ± 0% -3.95% (p=0.016 n=5+4) BTreeIterOverlapScan-16 34.2µs ± 1% 31.2µs ± 1% -8.78% (p=0.008 n=5+5) name old alloc/op new alloc/op delta BTreeIterFirstOverlap/count=16-16 96.0B ± 0% 0.0B -100.00% (p=0.008 n=5+5) BTreeIterFirstOverlap/count=128-16 96.0B ± 0% 0.0B -100.00% (p=0.008 n=5+5) BTreeIterFirstOverlap/count=1024-16 96.0B ± 0% 0.0B -100.00% (p=0.008 n=5+5) BTreeIterFirstOverlap/count=8192-16 96.0B ± 0% 0.0B -100.00% (p=0.008 n=5+5) BTreeIterFirstOverlap/count=65536-16 96.0B ± 0% 0.0B -100.00% (p=0.008 n=5+5) BTreeIterNextOverlap-16 0.00B 0.00B ~ (all equal) BTreeIterOverlapScan-16 144B ± 0% 48B ± 0% -66.67% (p=0.008 n=5+5) name old allocs/op new allocs/op delta BTreeIterFirstOverlap/count=16-16 1.00 ± 0% 0.00 -100.00% (p=0.008 n=5+5) BTreeIterFirstOverlap/count=128-16 1.00 ± 0% 0.00 -100.00% (p=0.008 n=5+5) BTreeIterFirstOverlap/count=1024-16 1.00 ± 0% 0.00 -100.00% (p=0.008 n=5+5) BTreeIterFirstOverlap/count=8192-16 1.00 ± 0% 0.00 -100.00% (p=0.008 n=5+5) BTreeIterFirstOverlap/count=65536-16 1.00 ± 0% 0.00 -100.00% (p=0.008 n=5+5) BTreeIterNextOverlap-16 0.00 0.00 ~ (all equal) BTreeIterOverlapScan-16 6.40 ± 9% 5.00 ± 0% -21.88% (p=0.008 n=5+5) ```
Member
sumeerbhola
approved these changes
Feb 26, 2020
Collaborator
sumeerbhola
left a comment
There was a problem hiding this comment.
Reviewed 7 of 7 files at r2.
Reviewable status:complete! 1 of 0 LGTMs obtained
Contributor
Author
|
bors r+ |
Contributor
Build succeeded |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #45276.
Prior to this change, the argument provided to
iterator.FirstOverlapwas stored in the iterator. This caused the argument to escape to the heap (if the parameterized type was a pointer) and would force an allocation if the argument was not already on the heap. This was not the intention and was causing issues in #45276.This commit fixes the issue by no longer storing the argument in the iterator's
overlapScanobject. This allows escape analysis to determine that the argument does not escape, like it was already doing foriterator.SeekGEanditerator.SeekLT.