swift icon indicating copy to clipboard operation
swift copied to clipboard

Incremental building?

Open MihaelIsaev opened this issue 4 years ago • 10 comments

I realized that even if I change one tiny letter somewhere in some string variable in my project it rebuilds completely, I mean that it seems that it never builds incrementally.

I use this command to build my project

swift build -c debug --product Run --enable-test-discovery --triple wasm32-unknown-wasi

My project is big so building takes ~40 seconds everytime... and it is kinda long time for development experiments.

Is there maybe some magic keyword to enable incremental building or it is just impossible with --triple wasm32-unknown-wasi?

MihaelIsaev avatar Feb 14 '21 22:02 MihaelIsaev

If you pass a -v flag to your swift build invocation, it will print exact commands for the build. Would you be able to infer which one takes the most time from that in your project? I guess that would be linking for big projects, but I'm curious what's actually taking so long in your case?

MaxDesiatov avatar Feb 14 '21 23:02 MaxDesiatov

Additionally, do you see similar build times for other triples?

MaxDesiatov avatar Feb 14 '21 23:02 MaxDesiatov

I guess that would be linking for big projects, but I'm curious what's actually taking so long in your case?

Yeah it seems that linking takes that long time cause it shows all the commands in first 3 seconds, and then it stays 37 more seconds without showing any additional commands and linking is the last command.

Additionally, do you see similar build times for other triples?

I'd love to, but could you tell how to build for other triples?

I tried to build the project with just swift build -c debug --product Run --enable-test-discovery:

Initial building takes ~50 seconds Incremental ~3 seconds

MihaelIsaev avatar Feb 15 '21 10:02 MihaelIsaev

I'd love to, but could you tell how to build for other triples?

I tried to build the project with just swift build -c debug --product Run --enable-test-discovery:

Initial building takes ~50 seconds Incremental ~3 seconds

Yes, I mean the host platform by "other triples", not passing any triple is perfectly fine for that.

That's interesting, I guess our default Wasm linker could be slow for large binaries, especially considering that we have to link everything statically.

@kateinoigakukun do you know if we could expect static linking when targeting Wasm to be slower than dynamic linking on other platforms?

MaxDesiatov avatar Feb 15 '21 10:02 MaxDesiatov

In my case the most of the code and swift files are inside the library that I wrote and maybe I could mark that library somehow so --triple wasm32-unknown-wasi will not relink it everytime?

MihaelIsaev avatar Feb 15 '21 10:02 MihaelIsaev

With static linking there's no way to avoid relinking, as far as I'm aware. In the end you get a single self-contained binary with everything embedded in it, so every time one of the constituent parts change, we have to embed them again to get a completely new binary. There may be some opportunities for caching, but I'm not aware of those.

Maybe @kateinoigakukun can clarify, as he previously has written a Wasm linker, albeit for slightly different purposes.

MaxDesiatov avatar Feb 15 '21 10:02 MaxDesiatov

I've just checked one theory.

I had 915 files in my lib and I glued most of them into several huge files, so I reduced amount of files to 361 and now incremental build takes only 12 seconds. It is really cool, but now I have few non-maintainable files ~20000 lines each.

MihaelIsaev avatar Feb 15 '21 19:02 MihaelIsaev

This is interesting, but I'm not sure why this takes much less time for non-Wasm builds, if I understand correctly what you posted above. We didn't make any changes to how incremental builds work in our fork, as far as I'm aware. Are you using SwiftWasm 5.3.1 or some development snapshot?

MaxDesiatov avatar Feb 15 '21 19:02 MaxDesiatov

carton says that I use swift-wasm-5.3.1-RELEASE

I checked non-Wasm build again and like no changes here, it is still: 45 seconds for initial build 3 seconds for incremental build

MihaelIsaev avatar Feb 15 '21 19:02 MihaelIsaev

This is with 915 files

Screenshot 2021-02-15 at 23 31 20

This is with 361 files

Screenshot 2021-02-15 at 23 33 23

but amount of code is absolutely the same in both cases

MihaelIsaev avatar Feb 15 '21 19:02 MihaelIsaev

I think it's already fixed. Feel free to re-open if not.

kateinoigakukun avatar Aug 26 '24 04:08 kateinoigakukun