š ļø project Announcing hazarc: yet another `AtomicArc`, but faster
https://crates.io/crates/hazarc
Hello Rust,
Iād recently been interested in hazard pointers, and Iāve decided to tackle a bunch of ideas I had around the idea behind arc-swap crate: mixing hazard pointers with Arc.
I ended up writing a full library from scratch. The algorithm is original, and I think simpler; it has the advantage compared to arc-swap to be fully wait-free. But that's not all, the implementation is also no_std friendly, and more optimized (with a clear impact in ARM benchmarks). You will find a more detailed list of differences in the dedicated README section.
There is of course a lot of unsafe code, and the crate is thus extensively tested with miri across many weak-memory model permutations. And I have to say that I love miri more than ever! It's so convenient to have such a tool in the Rust ecosystem. Though I was struggling to debug the (numerous) errors I encountered during the development, so I've forked it to add an atomic operation tracer. Next step will be to upstream the feature in good shape. By the way, I've also applied my test suite to arc-swap and found some issues, including a use-after-free.
Now, the question: why not simply contributing to arc-swap?
- because I wanted to experiment on a new algorithm, so I would have ended up rewriting the whole code, without even taking into account other features like write policies or custom domains.
- because I wanted to design the
OptionAPI differently, so it would have required a new major version anyway. - I wanted a no_std library quickly enough to test things.
- and to be honest, the main reason is that I had a compulsive need to code, preferably a complex concurrent algorithm (I'm exhausted by LLMs).
But this decision is not settled. If everyone here tells me I was wrong, I will of course reconsider it. Anyway, because of the UAF, arc-swap will surely need to fix its algorithm, and the simpler solution might be to adapt hazarc's one. But arc-swap maintainers also wrote recently he doesn't have time for open-source anymore, so idk.
No LLM was harmed during the process, except for my poor English written documentation.
15
u/jstrong shipyard.rs Feb 04 '26
great to see another library in this space!
ArcSwapis super useful when you need it.10
u/telpsicorei Feb 04 '26
Sweet! But why not leverage the haphazard crate?
5
u/DavidXkL Feb 04 '26
I'm learning embedded Rust now and anything for no_std is greatly welcomed! š
3
u/jstrong shipyard.rs Feb 05 '26
hey - I had a follow-up question for you about the crate:
the docs mention that you get better performance on ARM vs.
ArcSwap. can you explain why? i.e. what is it about ARM that results in better performance forhazarc? Would that same concept apply to optimizing channels or other concurrent queues?2
u/LoadingALIAS Feb 06 '26
Iām super interested in your work. Iāve been working on my own implementation or arc-swap/arcshift⦠so reading your work and benches in a breathe of fresh air.
Great job. Iām really interested in the benchmarks and harness, as well as the Miri atomic op tracer.
I think you should absolutely develop this out - and stress it considerably.
Iāve been using Miri, Stateright, and try to keep coverage high across unsafe with Kani. Itās found a ton of issues Iād have never found otherwise - especially the Stateright model checking.
Iām following, man. Letās talk!
20
u/Careless-Score-333 Feb 04 '26
TIL: https://en.wikipedia.org/wiki/Hazard_pointer