jonhoo / jonhoo/drwmutex

Is it reasonable to use runtime.fasthash on platforms other than linux_amd64?

Open
#10 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
356
Forks
17
PR merge metrics
No merged PRs in 30d

Description

Since drwmutex is mainly to improve the performance of read-most workload, use a fast hash function also can distribute the lock evenly, which may help to reduce lock contention.
Benchmark shows cost of runtime.fasthashn is very cheap.
```golang
func BenchmarkCpuid(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = cpu()
}
}

func BenchmarkFastrand(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = fastrandn(CPU_COUNT)
}
}

func cpu() uint64

//go:noescape
//go:linkname fastrandn runtime.fastrandn
func fastrandn(x uint32) uint32
```
```text
goos: darwin
goarch: amd64

BenchmarkCpuid-12 16798030 66.3 ns/op
BenchmarkFastrand-12 504372906 2.39 ns/op

goos: linux
goarch: amd64

BenchmarkCpuid-4 1471983 813 ns/op
BenchmarkFastrand-4 324570566 3.58 ns/op
```

So is it reasonable to use this rand method to choose read lock on platforms other than linux_amd64?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.