Announcing hazarc: yet another `AtomicArc`, but faster

66 points wyf0 10 comments

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 Option API 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.