January 5th, 2025

Size Optimization Tricks (2022)

The blog post discusses techniques for optimizing binary sizes in programming languages, emphasizing the Cosmopolitan codebase and advocating for efficiency, simplicity, and a cultural shift towards minimizing software complexity.

Read original articleLink Icon
Size Optimization Tricks (2022)

The blog post discusses various techniques for optimizing the size of binaries in programming languages like C, C++, and Python, particularly through the use of x86 assembly. The author highlights the Cosmopolitan codebase, which has garnered interest from the ELKS project for its efficient coding practices. The post emphasizes the importance of small binaries, which facilitate rapid testing and deployment across multiple operating systems. Techniques such as field arrangement, run-length encoding, dead code elimination, and overlapping functions are explored as methods to reduce binary size. The author advocates for a coding philosophy that prioritizes efficiency and simplicity, arguing that smaller binaries not only enhance performance but also improve the developer experience. The post concludes with a call for a shift in software development culture towards minimizing bloat and complexity, suggesting that a focus on size optimization can lead to more enjoyable and productive coding practices.

- Size optimization techniques can significantly reduce binary sizes in programming.

- The Cosmopolitan codebase serves as a model for efficient coding practices.

- Smaller binaries enhance testing speed and deployment across various operating systems.

- Techniques like run-length encoding and field arrangement can lead to substantial size reductions.

- A cultural shift in software development towards minimizing complexity is encouraged.

Link Icon 4 comments
By @nokeya - 11 days
All this assembly tricks are interesting but not really useful in real production code. Part about the struct packing is quite common and used but I don’t understand why these extra paddings are present and why one is gone. Even with pragma pack 8, should not it be only one padding?
By @bsenftner - 11 days
Justine Tunney just blows my mind, I think she is one of the most important software developers / computer scientists alive today.
By @nokeya - 10 days
Do anyone know any tools (static or dynamic analysers) to automatically detect structures/classes they may be reordered to improve their packing? I think it can be quite useful or at least interesting
By @secondcoming - 11 days
Here's one person trying to reduce binary bloat, while there's also a push to statically link everything. Who will win?

Alos, don't go rearranging the members of your structs if they're made public to third-parties!