It would be a shame to end the conversation with this, as it is a good
proposal, so I investigated it in more detail. The following was added to
config/config.nims from the Nim compiler devel branch and compared before the
change. (I am ashamed to admit that my last post seemed completely amateurish,
so I have made a few corrections.)
when defined(linux) and findExe("mold").len > 0:
switch("passL", "-fuse-ld=mold")
when defined(macosx) and findExe("ld64.mold").len > 0:
switch("passL", "-fuse-ld=ld64.mold")
Run
Nim devel 1st: $ time ./build_all.sh real 7m5.153s user 6m30.020s sys 1m1.229s
Nim devel 2nd: $ time ./build_all.sh real 7m3.367s user 6m10.247s sys 0m56.155s
Nim(changed) 1st: $ time ./build_all.sh real 6m45.184s user 6m12.736s sys
0m54.609s
Nim(changed) 2nd: $ time ./build_all.sh real 6m46.392s user 6m15.836s sys
0m56.464s
Obviously completed faster. about 15sec. The environment used is a laptop with
Ubuntu 22.04 WSL and a power-saving AMD Ryzen 5800U CPU. The version of mold is
1.7.0. (I also tried to see if Nim would compile with an older version. The
version I used was ver 1.0.3 installed by apt install mold on Ubuntu 22.04, but
I was able to link it successfully.)
I think that suddenly changing the default linker of the C processing system
has a large impact, so I think that individual developers need to put in the
above settings and verify them. I don't know how many committers there are, but
even assuming 20, that would save 90 hours a year if they compile 3 times a
day. Of course, it doesn't mean that they are doing nothing while waiting for
the compile, but even a few seconds of waiting time for a busy Nim compiler
developer can be reduced, which has its own impact.
Using "mold" will change the SHA1 of the binary, so the executable created will
be different from the default linker, but since it does not change the compiler
code, the impact should be minor.
Other notes: I compiled mold's main with a different Makefile and
-march=native, but it was too heavy and went out of control, so I did not try
it.
Sorry to take up so much time with the Nim developers, but I think it's a good
suggestion and would like to send a pull request, what do you think? If there
are any comments such as "This pattern case is missing and needs to be further
verified," or "The linker change to release build is hasty and should be
limited to debug first," we would like to correct it.
I have sent a PR to the mold side to ask them to include it in the README.md. I
don't know if it will be merged yet. <https://github.com/rui314/mold/pull/886>
Of course, Mr.Yardanico is right, it is not good to be deeply dependent on a
particular processing compiler or linker, but I would also like to lighten the
burden on the Nim developer a bit.