Cloudflare Workers Wasm Problems
Problems you will experience if you want to use Cloudflare Workers wasm.
Cloudflare workers still need more time. They are currently marked as WIP. Let's start by mentioning the scenarios where they are a good choice. You can use them in your projects that have manageable dependency management with a small file size and that you want to run fast. For example, you can write a simple proxy service or a service that serves static files. With wasm simd, you can make them into services that run very quickly and don't have scaling issues.
Now, let's talk about the FAQ section in its own documentation. All the questions asked in this section have been prepared to help you understand what you cannot do.
- Can I deploy a Worker that uses
- Currently no. All crates in your Worker project must compile to
wasm32-unknown-unknowntarget, which is more limited in some ways than targets for x86 and ARM64.
workercrate doesn't have X! Why not?
- Most likely, it should, we just haven't had the time to fully implement it or add a library to wrap the FFI. Please let us know you need a feature by opening an issue.
- My bundle size exceeds Workers size limits, what do I do?
- We're working on solutions here, but in the meantime you'll need to minimize the number of crates your code depends on, or strip as much from the
.wasmbinary as possible. Here are some extra steps you can try: https://rustwasm.github.io/book/reference/code-size.html#optimizing-builds-for-code-size
Let's start with the first question above. If you want to use
async_std, you cannot do this at the moment. You can use
async, there's no problem there. But you'll encounter errors because all the libraries you'll want to use depend on the two libraries mentioned above.
Suppose you have a crate you want to use, but you might find that it doesn't work. It could be due to the crate itself or one of its dependencies not targeting
wasm32-unknown-unknown. There's nothing you can do in this case. But you can point this out by opening an issue.
Finally, if you exceed the size limits, there's nothing you can do. The only thing you can do in this case is to minimize your dependencies. Even if you add one or two crates here, it will be very easy to exceed the size limits. The only thing you can do is to remove as much as possible from your
wasm binary. You can try the steps in this link for this. But this may not be enough; it wasn't enough in my use cases. As a second option here, the CF team can increase your limits specifically if you contact them. Or you can create your own
workerd environment and run it at the limits you want there.
In my opinion, Cloudflare workers are a great service. But they are not fully ready for use yet. There are many problems, especially with the limits. I believe that it will be a much better service once these problems are solved.
Note: If you believe there is anything missing or incorrect, please let me know.