3 ms·
> the compiler will be able to rip out all of the functions that they don't use Link-time optimization is already a thing. It's sad it doesn't seem to be used
by ronsor 6y ago
> the compiler will be able to rip out all of the functions that they don't use
Link-time optimization is already a thing. It's sad it doesn't seem to be used more often.
- yakubin 6y agoEven without LTO, linker will discard object files that aren't used (on Linux a static library is just an AR archive of object files). It's just a different level of granularity.
- floatboth 6y agoYou can get better granularity – build with -ffunction-sections, link with --gc-sections. LTO is really a much bigger deal, the main reason to use it is not throwing unused stuff away, but inlining across all the things.
- MereInterest 6y agoYes, but LTO doesn't apply across shared object libraries. Suppose I write a video game that uses DirectX for graphics, but I don't use the DirectX Raytracing feature at all. Because of DLL hell, I'm going to be shipping my own version of the DirectX libraries, ones that I know my video game is compatible with. Those are going to be complete DirectX libraries, including the Raytracing component, even though I don't use it at all in my game. No amount of LTO can remove it, because theoretically that same library could be used by other programs. On the other hand, if I am static linking, then there are no other programs that could use the static library. (Or, rather, if they do, they have their own embedded copy.) The LTO is free to remove any functions that I don't need, reducing the total amount that I need to ship.
- hdhrnnrkrkf 6y agoDirectX is a bad example, it's now a part of Windows and you don't ship it anymore.
- MereInterest 6y agoGood point (and shows that I am not a video game developer). I had tried to pick DirectX as something that would follow fao_'s example of game developers. The point still holds in the general case, though as you pointed out, not in the case of DirectX in particular.