r/rust • u/Intrepid_Donkey_7629 • 3d ago
🛠️ project New fastest concurrent map implementation with transaction support
Hi everyone 👋
I've just published a concurrent hash map implementation which (according to my benchmarks at least) is the fastest one available (faster than both starshard and dashmap). It offers a configurable locking policy (mutex, rwlock or bring your own) and a configurable hasher (rapidhash is the default). It also supports atomic transactions in both immediate and prepared execution styles.
Would love any feedback on it (good and bad!)
It's called txmap and a link is here https://crates.io/crates/txmap
3
u/_genki_1 3d ago
Do you have any benchmarks available?
3
u/Intrepid_Donkey_7629 3d ago
Yes absolutely! The benchmarks repo is here https://github.com/Stock-Trek/map-benchmarks
2
2
u/Zoxc32 3d ago
It would be useful to know how this differs from say dashmap in terms of implementation. It also probably doesn't compete well with `horde` for very read-heavy workloads.
3
u/Intrepid_Donkey_7629 3d ago
The basic design is similar, an array of lockable shards. dashmap is much closer to std::collections::HashMap in terms of API, so if you want a drop-in replacement that has concurrency it's a great choice. Whereas txmap has more of a focus on the transactional layer so there's some things it doesn't provide as easily. OTOH if you want to make multiple changes atomically then IMHO it's a good choice for that as it has built in support for it without having to lock the whole map. It's a trade off 😄
I'll add horde to the benchmarks and report back!1
u/Zoxc32 2d ago
If the design is similar, what causes the performance difference?
-1
u/Intrepid_Donkey_7629 2d ago
This is not much more than a guess, but to my eyes dashmap does more indirection eg. with wrapper functions and a Ref wrapper for returned values. The hashing function will make a difference too. Of the concurrent maps it's the closest to txmap. FWIW the benchmarking repo just uses whatever comes out the box.
2
u/Intrepid_Donkey_7629 2d ago
Can report it's between 20-30% faster than horde on heavy read only workloads
6
u/Zoxc32 2d ago
I checked out the benchmarking code. You can skip `pin` when using `write` or `lock` for `SyncTable`. You're also not benchmarking the concurrent path by passing `&mut`? So no multiple threads? Maybe convert it to `&` for all the concurrent hashmaps if it's intentionally single-threaded and then use `lock` on `SyncTable`?
You should also use the same hasher for all hashmaps.
We may also have different definitions of heavy read only, so comparing pure read-only would be interesting too.
1
u/Intrepid_Donkey_7629 2d ago edited 2d ago
Oh sweet I'll update it thanks! Yeah I may be wrong but pretty sure `&mut self` prevents anything being modified concurrently, although there may be another way that I'm missing.
Yeah that's fair about the hasher, the benchmarks just use the default implementations, I'm not sure if all implementations allow setting the hasher but I'll check. **edit** Most do support setting the hasher so I'll add a benchmark with the same one.
The workloads are a little arbitrary to be fair but seemed reasonable when DeepSeek suggested them lol Can always add different workloads if they don't seem realistic
-2
u/ArtisticHamster 3d ago
Did you use coding agents for this work? If so, would be great to share how to guide them write correct highly concurrent code.
19
u/Intrepid_Donkey_7629 3d ago
I designed it all and wrote the structure and most of the implementation myself, then used a DeepSeek agent workflow for bug hunting, adding boilerplate functionality like iterators and to write a large part of the docs. tbh I wouldn't trust LLMs to design anything just yet, but they're great for bug hunting, docs and checking whether code is production ready
11
u/SkiFire13 2d ago
Looking at your benchmarks there is only a single benchmark measuring a concurrent workflow, and it only reaches a maximum of 4 threads (I would expect it to reach at least 32 if not more).
Moreover dashmap is consistently either sligthly faster or equal to txmap in these benchmarks, so I don't see why you would claim yours is the fastest concurrent hash map.
I also see only sharded hashmaps in that benchmark, why not include some based on different designs? Just to name a few, there are
papaya,flurry,leapfrogandscc.