Build time

Dennis dkorpel at gmail.com
Fri Jul 23 20:03:22 UTC 2021


On Friday, 23 July 2021 at 18:53:06 UTC, JG wrote:
> Any suggestion on how to try and improve the build time. I am 
> currently using dub.

You can try profiling it with LDC 1.25 or later. Add this to 
dub.sdl:

```
dflags "--ftime-trace" platform="ldc"
dflags "--ftime-trace-file=./my-trace.json" platform="ldc"
postBuildCommands "import-chrome ./my-trace.json 
./my-trace.tracy" platform="ldc"
```

You can [get import-chrome and tracy 
here](https://github.com/wolfpld/tracy). There's binaries for 
Windows, and on Ubuntu/Debian Linux you can install as follows:

```
# Install required packages (there may be more, but this was the 
only one I didn't have installed yet)
sudo apt install libcapstone-dev

# Go to your code folder and clone tracy:
git clone https://github.com/wolfpld/tracy

# Build the import-chrome tool
cd tracy/import-chrome/build/unix/
make
# Copy it to the /usr/local/bin folder so it can be invoked from 
anywhere
sudo cp import-chrome-release /usr/local/bin/import-chrome

# Back to the root of the repo, now build the profiler
cd ../../../
cd profiler/build/unix/
make
sudo cp Tracy-release /usr/local/bin/tracy
```

Then do:
```
dub build --compiler=ldc2
tracy my-trace.tracy
```

And you can inspect what functions the compiler spends the most 
time on compiling. Sometimes there's one dumb thing taking a lot 
of time, so you can improve build times by working around that. 
E.g. I once replaced `std.conv: text` with `snprintf` to reduce 
my build time from 2.1 to 1.6 seconds.



More information about the Digitalmars-d-learn mailing list