-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add wasm32v1-none
support
#541
Conversation
6002c05
to
48d38ce
Compare
Current CI failure is unrelated. |
The CI failures are fixed in #542. |
f18f3b3
to
ff7a200
Compare
Hm, CI still has an unrelated failure. |
Yes, see rust-lang/rust#133401. We may disable the GNU/Hurd job since it's not the first time the UPD: Fixed in #543. |
84af741
to
604082a
Compare
604082a
to
a48e020
Compare
Rebased after #551 was merged. |
a48e020
to
56bd92a
Compare
How expensive is the Also, is it common to use one (non-trivial) WASM file in both Web and Node environments simultaneously, i.e. maybe we should split |
56bd92a
to
011d707
Compare
For Web that seems reasonable. NodeJS seems to be quite involved and I would argue that a thread-local is justified. EDIT: I will do some tests and get back to you.
AFAIK it is common to do it together. I'm not NodeJS expert, but whats strange to me is that the implementation is different to begin with. |
I've opened #557 to explore how such simplification could look like. Could you measure whether there is a measurable performance impact or not? |
I did some local benchmarking with Firefox and Chrome and I end up with around 40ns. Its only one FFI call after all, NodeJS is around 3 calls (I replaced the However, I didn't dig into the specifics on why the NodeJS implementation is so special, the API should be the same. My local testing shows that NodeJS works just fine with the browser API.
So all in all I think this is acceptable. I will add the implementation to that effect to this PR tonight. I also had a couple of optimizations in mind:
|
It's probably because a full Web Crypto support was added only in Node.js 19 (2022-10-18) and We had releases with WASM support a fair time before that, so we just kept the code as-is without considering whether the fallback is needed or not. I guess we can just drop the alternative Node.js path completely for the v0.3 release.
We also can continue with #557. I will leave the choice to you.
Can you demonstrate how this detection could look like? |
Sure, I'm a fan of splitting things up.
We can simply use |
Closing in favor of #557. |
As discussed in #541. This PR adds the following improvements: - Caching of the global `Crypto` object. - Detecting if our Wasm memory is based on a `SharedArrayBuffer`. If not, we can copy bytes directly into our memory instead of having to go through JS. This saves allocating the buffer in JS and copying the bytes into Wasm memory. This is also the most common path. `SharedArrayBuffer` requires `target_feature = "atomics"`, which is unstable and requires Rust nightly. See #559 (comment) for full context. - The atomic path only creates a sub-array when necessary, potentially saving another FFI call. - The atomic path will now allocate an `Uint8Array` with the minimum amount of bytes necessary instead of a fixed size. - The maximum chunk size for the non-atomic path and the maximum `Uint8Array` size for the atomic paths have been increased to 65536 bytes: the maximum allowed buffer size for `Crypto.getRandomValues()`. All in all this should give a performance improvement of ~5% to ~500% depending on the amount of requested bytes and which path is taken. See #559 (comment) for some benchmark results. This spawned a bunch of improvements and fixes in `wasm-bindgen` that are being used here: - rustwasm/wasm-bindgen#4315 - rustwasm/wasm-bindgen#4316 - rustwasm/wasm-bindgen#4318 - rustwasm/wasm-bindgen#4319 - rustwasm/wasm-bindgen#4340
Changes:
default-features = false
to thejs-sys
andwasm-bindgen-test
dependencies, enablingno_std
support.std
now enabledstd
crate features ofwasm-bindgen
,js-sys
andwasm-bindgen-test
.any(target_os = "unknown", target_os = "none")
instead oftarget_os = "unknown"
.thread_local!
is only supported withstd
, so a fallback tostatic
withonce_cell::unsync::Lazy
is added. This is safe because Wasm doesn't support threads withouttarget_feature = "atomics"
.target_feature = "atomics"
withoutfeature = "std"
, use#[thread_local]
.wasm32-unknown-unknown
is properly supported without pulling instd
.I was unable to add actual
no_std
tests without some ugly modifications to it. Especially because of the wholeharness = false
thing. Let me know how you want me to proceed.This depends on rustwasm/wasm-bindgen#4277 and a newwasm-bindgen
release.Was released.