Skip to content

Commit

Permalink
Reduce number of atomic loads (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
outofforest authored Dec 13, 2024
1 parent 2d8f202 commit 7069e9b
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 78 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
10 changes: 10 additions & 0 deletions space/address.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package space

import (
"sync/atomic"

"github.com/outofforest/quantum/types"
)

Expand All @@ -23,3 +25,11 @@ func isPointer(address types.VolatileAddress) bool {
func isData(address types.VolatileAddress) bool {
return !isFree(address) && !isPointer(address)
}

func load(address *types.VolatileAddress) types.VolatileAddress {
return (types.VolatileAddress)(atomic.LoadUint64((*uint64)(address)))
}

func store(address *types.VolatileAddress, value types.VolatileAddress) {
atomic.StoreUint64((*uint64)(address), (uint64)(value))
}
Loading

0 comments on commit 7069e9b

Please sign in to comment.