Skip to content

Commit

Permalink
util/interval/generic: avoid new allocations in btree benchmarks
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nvanbenschoten committed Feb 2, 2020
1 parent 1a3c232 commit f80ed60
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 f80ed60

Please sign in to comment.