Releases: puzpuzpuz/xsync
v3.4.0
- Add optimistic locking methods to RBMutex #138 and #140
- Fix Map/MapOf capacity calculation for WithPresize #139
RBMutex
now has methods for optimistic locking:
mu := xsync.NewRBMutex()
if locked, t := mu.TryRLock(); locked {
// critical reader section...
mu.RUnlock(t)
}
if mu.TryLock() {
// critical writer section...
mu.Unlock()
}
Thanks @kkroo for the contribution.
v3.3.1
- Add
NewMapOfWithHasher
function #137
Adds NewMapOfWithHasher
function to support custom hash functions in MapOf
:
m := NewMapOfWithHasher[int, int](func(i int, _ uint64) uint64 {
// Murmur3 finalizer. No DDOS protection as it does not support seed.
h := uint64(i)
h = (h ^ (h >> 33)) * 0xff51afd7ed558ccd
h = (h ^ (h >> 33)) * 0xc4ceb9fe1a85ec53
return h ^ (h >> 33)
})
Some custom hash functions may be faster than the built-in function if the lack of DDOS protection is fine.
Murmur3 finalizer:
BenchmarkMapOfInt_Murmur3Finalizer_WarmUp/reads=100%-8 525864650 2.240 ns/op 446360938 ops/s 0 B/op 0 allocs/op
BenchmarkMapOfInt_Murmur3Finalizer_WarmUp/reads=99%-8 383333918 3.127 ns/op 319827294 ops/s 0 B/op 0 allocs/op
BenchmarkMapOfInt_Murmur3Finalizer_WarmUp/reads=90%-8 267635385 4.535 ns/op 220506863 ops/s 0 B/op 0 allocs/op
BenchmarkMapOfInt_Murmur3Finalizer_WarmUp/reads=75%-8 181292007 6.448 ns/op 155092697 ops/s 2 B/op 0 allocs/op
Built-in hash function:
BenchmarkMapOfInt_WarmUp/reads=100%-8 431097415 2.858 ns/op 349837551 ops/s 0 B/op 0 allocs/op
BenchmarkMapOfInt_WarmUp/reads=99%-8 307244330 3.951 ns/op 253072903 ops/s 0 B/op 0 allocs/op
BenchmarkMapOfInt_WarmUp/reads=90%-8 226392990 5.306 ns/op 188477583 ops/s 0 B/op 0 allocs/op
BenchmarkMapOfInt_WarmUp/reads=75%-8 159236962 7.513 ns/op 133108546 ops/s 2 B/op 0 allocs/op
v3.3.0
- Speed up
MapOf
lookups #134 - Expose
Map
/MapOf
statistics #133 - Change license to Apache License 2.0 #135
Introduces meta memory and SWAR-based lookups similar to C++'s absl::flat_hash_map
hash table (https://abseil.io/docs/cpp/guides/container). The lookups are now up to 30% faster.
Also, reduces MapOf
's memory overhead: each bucket now holds up to 5 entries instead of 3.
Map
/MapOf
statistics are available via m.Stats()
. They may be used for diagnostic purposes.
v3.2.0
- Introduce Map/MapOf configs and grow-only option (#132)
Adds options support to the NewMap
/NewMapOf
functions. A MapOf
can now be created like this:
m := xsync.NewMapOf[int, int](WithPresize(100))
NewPresizedMap
/NewPresizedMapOf
functions are deprecated. Use the WithPresize
option instead.
Also, adds WithGrowOnly
option. It configures new Map
/MapOf
instance to be grow-only. This means that the underlying hash table grows in capacity when new keys are added, but does not shrink when keys are deleted. The only exception to this rule is the Clear
method which shrinks the hash table back to the initial capacity.
Grow-only maps are more efficient in the case of oscillating map size, i.e. when the map frequently grows and then shrinks in size.