dmd -run speed trends
Witold Baryluk
witold.baryluk at gmail.com
Sun Dec 17 06:53:25 UTC 2023
On Saturday, 16 December 2023 at 00:38:37 UTC, Siarhei Siamashka
wrote:
> Appears that linking Phobos as a static or a shared library
> makes a gigantic difference for this test. The shared library
> variant is much faster to compile. Changing `dmd.conf` in the
> unpacked tarball of the binary DMD compiler release to append
> `-L-rpath=%@P%/../lib64 -defaultlib=phobos2` makes `dmd -run`
> almost twice faster for me.
>
> ```
> [Environment32]
> DFLAGS=-I%@P%/../../src/phobos -I%@P%/../../src/druntime/import
> -L-L%@P%/../lib32 -L--export-dynamic -fPIC
> -L-rpath=%@P%/../lib32 -defaultlib=phobos2
>
> [Environment64]
> DFLAGS=-I%@P%/../../src/phobos -I%@P%/../../src/druntime/import
> -L-L%@P%/../lib64 -L--export-dynamic -fPIC
> -L-rpath=%@P%/../lib64 -defaultlib=phobos2
> ```
>
> And it's interesting that using the `mold` linker (via adding
> the `-Xcc=-fuse-ld=mold` option) appears to fail only when
> linking static 64-bit Phobos. Linking static 32-bit Phobos
> works, both shared 64-bit and 32-bit Phobos appear to work too.
Wow. That is enormous difference.
I was able to go from `278 ms` (no phobos imports, just some
`printf`), down to `88.3 ms`. And with `gold` linker down to
`80.2 ms`.
For the full original version (`std.stdio.writefln` and
`std.array.split`), it went from `723 ms` down to `499 ms`. And
with `gold` linker down to `477.5 ms`
So, `190 ms` shaved off. This is huge.
(This is with standard `ld.bfd` linker).
> Creating binaries that depend on the shared Phobos library
> isn't a reasonable default configuration. However it seems to
> be perfectly fine if used specifically for the "-run" option.
> Would adding an extra section in the `dmd.conf` file for the
> "-run" configuration be justified?
What?! I always (for a decade) tough that dmd by default links
dynamically phobos. I think it should definitively link
dynamically by default. Just like gcc, gdc, ldc, clang are doing
things. Compiling phobos statically by default does not really
solve versioning fully anyway, as one still have dependencies on
glibc, and such.
Also for fast edit + compile + run cycles, as well as running
unittests frequently, it definitively make sense to do dynamic
linking.
> Oh, and I already mentioned `rdmd` before. Burn this thing with
> fire!
That is "cheating". :) Yes, useful, but not for making sure
compiler is fast.
More information about the Digitalmars-d
mailing list