Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
44617: util/interval/generic: avoid new allocations in btree benchmarks r=nvanbenschoten a=nvanbenschoten

The generic template for interval btree makes an attempt to work with
both value and pointer parameterized types. To facilitate this option
in tests, it used reflection to create new instances of the item type.
This reflection was preventing allocations of the item type from being
inlined and avoided by escape analysis, which was skewing benchmarks.

This commit fixes this by avoiding the reflection and instead adding
a constructor to the contract of the parameterized type. This is cleaner
and allows the allocations to be avoided in these benchmarks.

Here's the new `benchdiff` output of the latch manager's btree from
before cockroachdb#43850 to after this change: [benchdiff sheet](https://docs.google.com/spreadsheets/d/1ZxtPPSWV0z76msCiwIyqL0xnUQF530ZwnbnfrvEzNAE/edit#gid=4).

Co-authored-by: Nathan VanBenschoten <[email protected]>
  • Loading branch information
craig[bot] and nvanbenschoten committed Feb 3, 2020
2 parents 1347bd4 + f80ed60 commit e49530d
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 139 deletions.
82 changes: 36 additions & 46 deletions pkg/storage/spanlatch/latch_interval_btree_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/storage/spanlatch/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func (la *latch) ID() uint64 { return la.id }
func (la *latch) Key() []byte { return la.span.Key }
func (la *latch) EndKey() []byte { return la.span.EndKey }
func (la *latch) String() string { return fmt.Sprintf("%s@%s", la.span, la.ts) }
func (la *latch) New() *latch { return new(latch) }
func (la *latch) SetID(v uint64) { la.id = v }
func (la *latch) SetKey(v []byte) { la.span.Key = v }
func (la *latch) SetEndKey(v []byte) { la.span.EndKey = v }
Expand Down
Loading

0 comments on commit e49530d

Please sign in to comment.