I'm seeing some behavior I don't understand in rebuilding / incremental debug builds when they're launched in different instances of the same shell. (bash)
Platforms tested on: Ubuntu 20.04, Windows + WSL + Ubuntu 22.04
Here is an example on vanilla Ubuntu 20.04, with no file modifications in between builds:
dkolas@bernard:~/projects/project-name$ swift build --build-tests Building for debugging... Build complete! (71.57s) dkolas@bernard:~/projects/project-name$ swift build --build-tests Building for debugging... Build complete! (1.69s) dkolas@bernard:~/projects/project-name$ bash dkolas@bernard:~/projects/project-name$ swift build --build-tests Building for debugging... Build complete! (72.52s)
Note that in the first and third builds, the line 'building for debugging' does not appear until 70s into the process, if that means something to anyone.
I don't understand why a rebuild in a new shell, with the same user, should behave any differently than a rebuild in a shell in which I've already built.
Things that don't seem like they're the issue:
- files / directories not in filesystem cache. Using
vmtouch, it appears that the whole project directory is more or less still in memory in a new shell.
- Dependency resolution - this generally creates terminal output, so I assume it's not happening in either case, and the same behavior can be seen when passing the --skip-update flag in the new shell
What I'd like to understand is:
- What is the step that's being silently done (or what's being cached the first time) such that the first rebuild in a new shell takes so much longer than the second?
- Is there a way to reuse the cache, or pass some flag to the build, such that this can be avoided?
The reason this is important to me is because VSCode on Windows + WSL appears to be effectively launching a new shell every time the build is run, so I'm paying that much longer cost for 100% of incremental rebuilds. On my main workstation, modifying one test file and rebuilding in the short case takes 1s, versus 30s in the long case, so it's a significant change in experience.