-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
Proposal Details
I'm working on a concurrent hash map and with me having experience in using them in highly concurrent contexts with high throughput requirements I knew to add batch Put and Get methods to it. Such API design exposes the very obvious opportunity for prefetching the data.
To experiment with the impact of internal/runtime/sys.Prefetch on the batch Get call I modified runtime/panic.go to expose the intrinsic. go tool objdump then confirmed that a PREFETCHT0 instruction is emitted into the binary as expected.
// in runtime/panic.go
func Prefetch(addr uintptr) {
sys.Prefetch(addr)
}
// and using it like this
for _, bucket := range initial_buckets_for_keys {
runtime.Prefetch(uintptr(unsafe.Pointer(bucket)))
}Looking up 100k distinct entries from a hash map with 5000k entries became significantly faster.
old: BenchmarkLookupBatches/size=100000-8 63.14 million_lookups/s
new: BenchmarkLookupBatches/size=100000-8 96.64 million_lookups/s
Which looks like a worthwhile optimization for me.
I personally like how for me this runtime.Prefetch Just Works™ so I propose adding just it. I also propose to not tell of it's addition in the change log so people don't use it willy-nilly. Just imagine the damage that all the blog spam will cause in the overall ecosystem, possibly leaking into other language communities too.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status