swiftwasm / swift

WebAssembly support for the Swift programming language
https://swiftwasm.org
1.28k stars 28 forks source link

Embedded Wasm Build Is Needlessly Slow #5585

Open filip-sakel opened 3 weeks ago

filip-sakel commented 3 weeks ago

I have a simple Wasm Embedded Swift package and even a minor change to a function results in a 12-second rebuild. I think that's because of 3 things: (1) forced release builds, (2) forced WMO disabling incremental builds, (3) forced symbol-elimination LTO. I know Swift already has slow compile times, but it's significantly worse with Embedded mode.

Now, I understand that Embedded is meant for constrained environments. And the Web is one such environment, having significant constraints in bundle and code size. However, during development, these constraints don't necessarily apply and I think it'd be a lot faster to generate an unoptimized binary to speed up debugging.

I've thought about using non-Embedded mode during development, but that has significant downsides. Firstly, I forgo the restrictions Embedded mode imposes, such as the lack of reflection capabilities. Also, regular Wasi code depends on Wasi-Libc (IIRC) which adds a lot of bloat, especially considering that it's only job is to define two or three functions the Swift stdlib uses.

I hope there is an easy solution where the compiler can still enforce Embedded mode's restrictions during type checking, but produces a (slightly larger) binary a lot more quickly. Again, I think that making some optimization optional would go a long way. Namely, we could allow code to compile in debug configuration with incremental builds and without necessitating LTO.

kateinoigakukun commented 3 weeks ago

It would be really helpful if you could give us a benchmark target project. Also, it seems like not Wasm-specific but general to Embedded targets, so it would be better to open in apple/swift repository to get more feedback