SteveSandersonMS / dotnet-wasi-sdk

Packages for building .NET projects as standalone WASI-compliant modules
519 stars 36 forks source link

More Aggressive Trimming #24

Closed stevefan1999-personal closed 2 years ago

stevefan1999-personal commented 2 years ago

It seems like the smallest hello world example I can produce here has a final artifact size of 15MB, and 6MB after aggressive wasm-opt, and 2MB after compression, which is still overwhelmingly huge to fit in the 1MB limit of Cloudflare Workers. So I was looking for more trimming opportunities, for example, would removing I18N help this kind of situation?

SteveSandersonMS commented 2 years ago

In the next update, it will strip out native wasm debugging symbols at link time, which will reduce the size of a basic ConsoleApp.wasm to about:

So, it's a significant improvement, but still a way off.

I'm guessing Cloudflare Workers' 1MB restriction is uncompressed, is it? Assuming so, I'm afraid we're not about to get under 1.0MB uncompressed any time soon. Possibly in the longer term future an entirely different compilation mechanism (such as .NET NativeAOT) might make that realistic but it's outside the realms of something to attempt soon.

If you were extremely determined you could theoretically embed the compressed data into a wasm module and decompress it at runtime, however that would be pretty expensive at runtime on every request. And even then you're still right on the threshold and would likely tip over it as soon as you add nontrivial application code or dependencies.

For the forseeable future, the most practical way forwards for you would be to request a larger worker size.

So I was looking for more trimming opportunities, for example, would removing I18N help this kind of situation?

Good but bad news - it already does that.

JeepNL commented 2 years ago

[UPDATE: Oops: I see it's a post from 7/7 - it's probably what you were talking about ..]

Just FYI, I read this tweet just now on Twitter. I don't know if this has anything to do with the size, I'm just sharing it here.

"Announcing support for WASI on Cloudflare Workers"

👉 https://blog.cloudflare.com/announcing-wasi-on-workers/

stevefan1999-personal commented 2 years ago

[UPDATE: Oops: I see it's a post from 7/7 - it's probably what you were talking about ..]

Just FYI, I read this tweet just now on Twitter. I don't know if this has anything to do with the size, I'm just sharing it here.

"Announcing support for WASI on Cloudflare Workers"

👉 https://blog.cloudflare.com/announcing-wasi-on-workers/

Exactly. But the 1MB restriction still applies. I have already been able to run .NET WASI in local dev mode.