Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The biggest reason is because it is multi-threaded. When building a program, the compilation step is parallelized (the build system invokes a compiler for each source file), but the final link step is not. So it is important to make the linker itself multi-threaded.

But even without multi-threading, mold is still faster than other linkers. I can think of various reasons why, but I don't know which attributes how much. I believe the biggest contributor is its efficient data structure -- it is hard to make program faster by writing fast code, but it can naturally be achieved by designing efficient data structures. That said, it is hard to compare two or more programs to find out why one program is faster than the others unless their designs are similar.



Note that recent lld is also multithreaded, and with tweaks, can be faster than mold at low core counts: https://bugzilla.mozilla.org/show_bug.cgi?id=1746462#c2


I wouldn't be surprised. In mold, if we have more than one choices to implement a feature, I always take the one that scales well for more cores even if it doesn't perform the best on low-core count machines.

My assumption is that future machines will have more cores than we have today on average, so I'm optimizing mold for such computers.


> My assumption is that future machines will have more cores than we have today on average, so I'm optimizing mold for such computers.

From the manpage of mold-1.3.0, I get the impression mold is designed to scale up to 32 cores, but not more.

  man mold | rg -C2 32
       --threads
       --no-threads
               Use multiple threads.  By default, mold uses as many threads as the number of cores or 32, whichever is the smallest.  The reason why it is capped to 32 is because mold doesn't scale well beyond that point.  To use only one thread, pass --no-threads or --thread-count=1.

Is this correct or does the manpage need to be updated?


Could you comment on which data structures are most critical to mold’s performance, and what makes them so fast?


Ah, I overlooked this explanation at first: https://github.com/rui314/mold/blob/main/docs/design.md

Thanks for the great write up as well as mold itself!




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: