Skip to content

Commit

Permalink
Reduce number of atomic loads
Browse files Browse the repository at this point in the history
  • Loading branch information
outofforest committed Dec 13, 2024
1 parent 527ec85 commit 8c798be
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (

func BenchmarkBalanceTransfer(b *testing.B) {
const (
numOfAddresses = 50_000_000
numOfAddresses = 5_000_000
txsPerCommit = 20_000
balance = 100_000
)
Expand Down
22 changes: 14 additions & 8 deletions space/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (s *Space[K, V]) SetKey(
volatileAddress := v.storeRequest.Store[v.storeRequest.PointersToStore-1].Pointer.VolatileAddress
s.detectUpdate(v, volatileAddress)

return s.set(v, tx, allocator)
return s.set(v, volatileAddress, tx, allocator)
}

// Stats returns space-related statistics.
Expand Down Expand Up @@ -278,10 +278,10 @@ func (s *Space[K, V]) find(v *Entry[K, V], volatileAddress types.VolatileAddress

func (s *Space[K, V]) set(
v *Entry[K, V],
volatileAddress types.VolatileAddress,
tx *pipeline.TransactionRequest,
volatileAllocator *alloc.Allocator[types.VolatileAddress],
) error {
volatileAddress := v.storeRequest.Store[v.storeRequest.PointersToStore-1].Pointer.VolatileAddress
volatileAddress = s.walkPointers(v, volatileAddress)

if isFree(volatileAddress) {
Expand Down Expand Up @@ -326,16 +326,19 @@ func (s *Space[K, V]) set(
v.level--
v.nextDataNode = nil

return s.set(v, tx, volatileAllocator)
volatileAddress = v.storeRequest.Store[v.storeRequest.PointersToStore-1].Pointer.VolatileAddress
return s.set(v, volatileAddress, tx, volatileAllocator)
}
}

// Add pointer node.
if err := s.addPointerNode(v, tx, volatileAllocator, conflict); err != nil {
var err error
volatileAddress, err = s.addPointerNode(v, tx, volatileAllocator, conflict)
if err != nil {
return err
}

return s.set(v, tx, volatileAllocator)
return s.set(v, volatileAddress, tx, volatileAllocator)
}

func (s *Space[K, V]) splitToIndex(parentNodeAddress types.VolatileAddress, index uint64) (uint64, uint64) {
Expand Down Expand Up @@ -501,10 +504,10 @@ func (s *Space[K, V]) addPointerNode(
tx *pipeline.TransactionRequest,
volatileAllocator *alloc.Allocator[types.VolatileAddress],
conflict bool,
) error {
) (types.VolatileAddress, error) {
pointerNodeVolatileAddress, err := volatileAllocator.Allocate()
if err != nil {
return err
return 0, err
}
s.config.State.Clear(pointerNodeVolatileAddress)

Expand All @@ -527,7 +530,10 @@ func (s *Space[K, V]) addPointerNode(
} else {
_, err = s.splitDataNodeWithoutConflict(tx, volatileAllocator, 0, pointerNodeVolatileAddress, v.level+1)
}
return err
if err != nil {
return 0, err
}
return pointerNodeVolatileAddress, nil
}

func (s *Space[K, V]) walkPointers(v *Entry[K, V], volatileAddress types.VolatileAddress) types.VolatileAddress {
Expand Down
2 changes: 1 addition & 1 deletion space/space_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Github actions run on machines not supporting AVX-512 instructions.
////go:build nogithub
//go:build nogithub

package space

Expand Down
3 changes: 2 additions & 1 deletion space/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ func (s *SpaceTest[K, V]) SplitDataNode(v *Entry[K, V], conflict bool) error {

// AddPointerNode adds pointer node.
func (s *SpaceTest[K, V]) AddPointerNode(v *Entry[K, V], conflict bool) error {
return s.s.addPointerNode(v, s.tx, s.allocator, conflict)
_, err := s.s.addPointerNode(v, s.tx, s.allocator, conflict)
return err
}

// Query queries the space for a key.
Expand Down

0 comments on commit 8c798be

Please sign in to comment.