Skip to content

Releases: puzpuzpuz/xsync

v3.4.0

14 Jul 11:13
5f67a12
Compare
Choose a tag to compare
  • 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

07 Jul 19:29
e96db0e
Compare
Choose a tag to compare
  • 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

06 Jul 09:26
55a8a3a
Compare
Choose a tag to compare
  • 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

22 Jun 05:43
ec68f42
Compare
Choose a tag to compare
  • 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.

v3.1.0

25 Feb 18:23
cdaca8b
Compare
Choose a tag to compare
  • Use presized Map/MapOf argument as the minimal map capacity (#121)

NewMapPresized/NewMapOfPresized's argument is now treated as the minimal table capacity. The underlying hash table won't shrink beyond the specified capacity.

Also, fixes and improves godoc.

v3.0.2

14 Nov 17:11
1386eb4
Compare
Choose a tag to compare
  • Fix too aggressive Map/MapOf shrinking on deletion leading to out of range panic (#113)

Thanks @mdumandag for reporting the issue.

v3.0.1

01 Nov 19:07
42e3390
Compare
Choose a tag to compare
  • Fix lost updates on concurrent Map/MapOf resize (#111)

Thanks @klauspost for reporting this issue.

v3.0.0

22 Oct 12:24
f7bf836
Compare
Choose a tag to compare
  • Replace the user-defined hash function in MapOf factories with a built-in fast hash function (#107, #108)

All New*MapOf* functions are now replaced with the NewMapOf and NewMapOfPresized functions. There is no longer a need to provide a user-defined hash function.

Kudos go to @destel

v2.5.1

26 Sep 18:44
c3b5020
Compare
Choose a tag to compare
  • Speed up built-in string hash function (#106)

v2.5.0

21 Aug 08:06
ace0f0f
Compare
Choose a tag to compare
  • Add concurrent queue with generics support (MPMCQueueOf) (#104)