Shrinking While Linking

tweag.io

40 points by ingve 5 days ago


lionkor - 16 hours ago

> Back in the day, your compiler or assembler would turn each source file into an “object” file containing the compiled code.

Lots and lots of code is still C and C++. That's not really "back in the day".

nextaccountic - 12 hours ago

The real problem are generics. They cause a blowup in size because they are instantiated at every type combination that is actually called. This can sometimes be a performance boost (typically not because it avoids an indirect call, but because it enables optimizations such as inlining). But it can also makes code slower (not by much), or have little effect on performance

Rust lets you choose between generics and trait objects, but this is a viral change that sometimes means that large sections of code must be rewritten. There is also an optimization that turns generics into virtual dispatch if deemed beneficial, but I'm not sure how well it works

Joker_vD - 14 hours ago

> A static library is nothing but a bundle of object files, wrapped in an ancient and never-quite-standardized archive format.

To this day I'm astonished that it's not just tar. Or pax. Or even cpio! Or literally any file format that has any other use.

kragen - 16 hours ago

These are extremely practical tips on using binutils to shrink your libraries. It might also be worthwhile to compile the library without per-function sections in the first place, which hopefully can be done without patching rustc. On many platforms this produces significantly smaller code in GCC.