Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I optimize for size (-Os) for an I/O application

Tags:

performance

c

gcc

I have a C application that is heavily network I/O bound. It is currently compiled with -O2 on gcc. Building the application with -Os shows gives a 20% size reduction. Some basic testing showed no measurable decrease (or increase) in performance.

Is this a good case for building with -Os? Is there a reason not to do this? I've never actually seen a program that has been compiled for size no matter how much time it spends on I/O.

like image 434
Remus Avatar asked Sep 28 '22 04:09

Remus


1 Answers

Optimization shouldn't affect the program's operations. Therefore, no type of optimization should affect network I\O used by the program, and anything else for that matter. If your program sends 10 kilobytes, it will send the same even after optimization.

Optimization may affect the way structs are aligned among other things (like the size of the code, memory usage and more) but won't affect the logic at all (if programmed correctly).

Generally, as binary files tend to be relatively small (a 1MB binary file is an extremely large one) it is more common to optimize for speed rather than size. However, it is up to you.

like image 200
Mark Segal Avatar answered Nov 24 '22 04:11

Mark Segal