alphadose / haxmap

Fastest and most memory efficient golang concurrent hashmap
MIT License
892 stars 45 forks source link

Add xsync MapOf to benchmarks #22

Closed puzpuzpuz closed 1 year ago

puzpuzpuz commented 1 year ago

Adds xsync MapOf to the benchmarks to have one more map in the comparison.

Results on my machine are the following:

$ go test -benchmem -bench .
goos: linux
goarch: amd64
pkg: github.com/alphadose/haxmap/benchmarks
cpu: 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
BenchmarkHaxMapReadsOnly-8                174625          6876 ns/op           0 B/op          0 allocs/op
BenchmarkHaxMapReadsWithWrites-8          149389          7895 ns/op         963 B/op        120 allocs/op
BenchmarkGoSyncMapReadsOnly-8              60259         19771 ns/op           0 B/op          0 allocs/op
BenchmarkGoSyncMapReadsWithWrites-8        52824         22527 ns/op        4874 B/op        452 allocs/op
BenchmarkCornelkMapReadsOnly-8            178738          6657 ns/op           0 B/op          0 allocs/op
BenchmarkCornelkMapReadsWithWrites-8      150156          8103 ns/op        1026 B/op        128 allocs/op
BenchmarkXsyncMapReadsOnly-8              294196          3993 ns/op           0 B/op          0 allocs/op
BenchmarkXsyncMapReadsWithWrites-8        241662          4698 ns/op         922 B/op         57 allocs/op
PASS
ok      github.com/alphadose/haxmap/benchmarks  10.413s
bagualing commented 1 year ago

Wow, xsync is knocking on the door. The latest update of xsync has a significant performance boost.

puzpuzpuz commented 1 year ago

@bagualing thanks. Yeah, MapOf got more efficient in scenarios when the data set is small in the latest version.

alphadose commented 1 year ago

@puzpuzpuz really great work, I will definitely check out xsync map implementation in more depth

I will also see if current haxmap performance can be improved from drawing inspiration from xsync map

puzpuzpuz commented 1 year ago

I will definitely check out xsync map implementation in more depth

That would be awesome. You should be looking into MapOf (generic map) as it's different from Map (non-generic map). MapOf overall design is quite simple: a hash table of cache-line-sized buckets holding key hashes + pointers to immutable key-value pairs. Each bucket is organized in a unrolled linked list and protected with a sync.Mutex. The rehashing involves a bit tricky synchronization, but still not very complicated.