kanidm / concread

Concurrently Readable Data Structures for Rust
Mozilla Public License 2.0
343 stars 15 forks source link

Better wasm support #75

Closed ghost closed 2 years ago

ghost commented 2 years ago

This crate does not compile to wasm as-is due to a dependency on ahash or rather its dependency getrandom. It is relatively easy to get it to compile by pinning the getrandom dependency with the js feature. It would be nice to not need to do this, ie. this crate could support a different hash algorithms like wyhash which only depends on rand-core and compiles to wasm without issue.

Firstyear commented 2 years ago

Hey @mockfox what are you trying to achieve using this crate inside of wasm? Most of the value here is in multi-threaded contexts, so I'm wondering if you just are after the concurrently readable cell types, or if you really want all the hashtrie/hashmap functionality. That'll help me know what the right thing to do is to fix this.

ghost commented 2 years ago

At the moment, I am using HashMap although the other concurrent types would also be useful in other projects. I am using it in a multithreaded context (wasm_bindgen_futures).

Firstyear commented 2 years ago

So I think the best option in this case is:

That should let you use this with wasm, provided you set --default-features=false.

How does that sound?

EDIT: I'm skeptical to change default hashers by default by ahash is the 'fastest' hasher on other platforms, and in the review wyhash is not dos resistant https://github.com/tkaitchuck/aHash/blob/master/compare/readme.md

ghost commented 2 years ago

It does make sense to use the std hasher when the ahash feature is disabled, just to get the crate to compile to wasm on its own with a DOS resistant hash by default. I think that suggesting wyhash perhaps should have been a separate issue; I typically do not need DOS resistant hashes. It would be nice to be able to enable an alternative like wyhash as a feature.

Firstyear commented 2 years ago

Done! Please upgrade to 0.3.4, and you'll find all the features there. Should also be documented on docs.rs.