Skip to content

v4.1.0

Latest
Compare
Choose a tag to compare
@puzpuzpuz puzpuzpuz released this 03 May 05:21
f6258c7
  • New data structure: UMPSCQueue #168
  • Speed up LoadAndDelete and Delete in case of non-existing Map key #167
  • Parallel Map resize #170

UMPSCQueue is meant to serve as a replacement for a channel. However, crucially, it has infinite capacity. This is a very bad idea in many cases as it means that it never exhibits backpressure. In other words, if nothing is consuming elements from the queue, it will eventually consume all available memory and crash the process. However, there are also cases where this is desired behavior as it means the queue will dynamically allocate more memory to store temporary bursts, allowing producers to never block while the consumer catches up.

From now on, Map spawns additional goroutines to speed up resizing the hash table. This can be disabled when creating a Map with the new WithSerialResize setting:

m := xsync.NewMap[int, int](xsync.WithSerialResize())
// resize will take place on the current goroutine only
for i := 0; i < 10000; i++ {
	m.Store(i, i)
}

Thanks @PapaCharlie and @llxisdsh for the contributions!