Reality Check for Cloudflare Wasm Workers and Rust
11–20 of 59 posts
Re: Reality Check for Cloudflare Wasm Workers and Rust
#12Earlier quoted context omitted.
I for one hadn't thought about the cost of shipping your own standard library with every bundle, so it was informative for me
WASM tasks shouldn’t need a full standard library. If you statically compile against any library it should only keep the pieces used.
Re: Reality Check for Cloudflare Wasm Workers and Rust
#13> I guess I’ll stick with my error prone Javascript Workers or, more likely, spend an afternoon migrating to a minimal Typescript setup. If the OP wants a zero-config typescript experience (assuming Deno isn't available on Cloudflare workers), I can't recommend esbuild enough
There's also js_of_ocaml if a good type system is desired.
Re: Reality Check for Cloudflare Wasm Workers and Rust
#14Re: Reality Check for Cloudflare Wasm Workers and Rust
#15Correct me if I’m wrong but the memory copying issue is not an issue if you pass an array buffer into WASM from JavaScript. In that scenario there’s no data copying. E.g. similar to how you’d pass the canvas data to WASM for direct manipulation.
All wasm instructions can do is read and write from the wasm Memory that the wasm is initialized with. They can't even refer to separate things like a new ArrayBuffer from JS. So you do need to copy.
Newer wasm additions like reference types allow an ArrayBuffer to be referred to inside wasm, but only as an opaque reference to the entire thing (an externref). There is still no ability to actually read and write from it inside wasm.
The solution to this is BYOB ("bring your own buffer") APIs, which JS is adding. They are experimental atm though. Here is the relevant one here:
https://developer.mozilla.org/en-US/docs/Web/API/ReadableStr...
Note how you pass in a view to the JS API. That can be a view into the wasm memory, letting the browser directly write data into there, and then wasm can operate on it immediately.
Re: Reality Check for Cloudflare Wasm Workers and Rust
#16I think the one-sentence version of this is that Workers are meant for small, undemanding tasks (for example, they have tight memory limits and don’t have great performance), so using them to do “serious number crunching” at the edge, which is the advertised use case, seems questionable. I think the blurb about the downsides of Wasm is just too generic, it’s a sort of “why Wasm isn’t preferable to JS in all cases” fo…
> I think the one-sentence version of this is that Workers are meant for small, undemanding tasks (for example, they have tight memory limits and don’t have great performance) That could be most web apps functionalities. Things like registration, authorization/authentication, sending emails, store/retrieve data, etc... > so using them to do “serious number crunching” at the edge, which is the advertised use case, see…
https://developers.cloudflare.com/workers/platform/cron-trig...
Re: Reality Check for Cloudflare Wasm Workers and Rust
#17Earlier quoted context omitted.
I for one hadn't thought about the cost of shipping your own standard library with every bundle, so it was informative for me
WASM tasks shouldn’t need a full standard library. If you statically compile against any library it should only keep the pieces used.
Re: Reality Check for Cloudflare Wasm Workers and Rust
#18Correct me if I’m wrong but the memory copying issue is not an issue if you pass an array buffer into WASM from JavaScript. In that scenario there’s no data copying. E.g. similar to how you’d pass the canvas data to WASM for direct manipulation.
Re: Reality Check for Cloudflare Wasm Workers and Rust
#19Earlier quoted context omitted.
WASM tasks shouldn’t need a full standard library. If you statically compile against any library it should only keep the pieces used.
I'm not sure but if you need any string manipulation at all it will be really hard to not use the rust std?
Re: Reality Check for Cloudflare Wasm Workers and Rust
#20> I guess I’ll stick with my error prone Javascript Workers or, more likely, spend an afternoon migrating to a minimal Typescript setup. If the OP wants a zero-config typescript experience (assuming Deno isn't available on Cloudflare workers), I can't recommend esbuild enough
There's also js_of_ocaml if a good type system is desired.