3 ms·
For the uninitiated: LTO stands for Link-time optimization and happens when the compiler merges/links all separately-compiled object files into one (executable
by hf 12y ago
For the uninitiated: LTO stands for
Link-time optimization and happens when the compiler
merges/links all separately-compiled object files
into one (executable or library).
Although it seems obvious that this might be a good idea,
why would it
1) use exorbitant amounts of memory; and
2) be "pretty awesome" instead of, say, mildly useful?
edit: And both questions satisfactorily answered
in the time it took me to peruse the preamble of
https://en.wikipedia.org/wiki/Interprocedural_optimization https://en.wikipedia.org/wiki/Interprocedural_optimization
Thank you!
- mattgrice 12y agoLink-time optimization is not a very descriptive term. It's usually called whole-program or interprocedural optimization. Link-time optimization is just how it has been implemented. It uses a lot of memory because it requires keeping a representation of more or less the entire program in memory at one time, in a format which is amenable to analysis. It is not out of the ordinary for an optimizer's internal representation to be on the order of 1000x the size of the source code.
- anaphor 12y agoFor an example of a compiler other than GCC that does whole-program optimization see the Stalin Scheme compiler: https://github.com/barak/stalin https://github.com/barak/stalin
- dietrichepp 12y agoLTO, as the name implies, means that you do another optimization pass at link time. This enables lots of optimizations that don't work when you look at one module at a time. Functions can be inlined across module boundaries, even when they're not declared inline. You can turn virtual functions into regular functions, if you know that the virtual function is never overridden, or if you can derive the exact type. You can change calling conventions for functions. You can do better escape and aliasing analysis. If a function is only called once, then you can probably optimize it a lot better because you know exactly how it will be called. As with all optimizations, not all programs will see any significant benefit. Programs with heavy inner loops like physics simulators and graphics processors will not see much benefit, since the local optimizer works well enough. Programs like compilers, interpreters, and web browsers will see larger benefits. However, the benefits can be high—30% improvements in running time are not unheard of. In short, LTO is a high-cost, high-benefit optimization.