Author Topic: Smaller executables  (Read 2646 times)

0 Members and 1 Guest are viewing this topic.

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Smaller executables
« on: May 15, 2019, 07:56:48 pm »
There's a QB64 compiler option I used once that knocked a meg off the file size, and I forgot what the
parameter was.  Does anyone know it?

I realize file size barely matters these days with HD space being so cheap, and upload speeds being so
fast, but smaller exe file sizes slightly alleviate the fear of a virus.
It works better if you plug it in.

Offline Raven_Singularity

  • Forum Regular
  • Posts: 158
    • View Profile
Re: Smaller executables
« Reply #1 on: May 16, 2019, 02:18:11 am »
UPX can significantly shrink the executable for you, and works on Mac, Win, Lin.

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Smaller executables
« Reply #2 on: May 16, 2019, 04:34:39 am »
I'd added "eco" to the filename and now I realize what it must be - " error code off", which I tested  when I learned of it.
But adding in $CHECKING:OFF isn't causing shrinkage like an entire meg, only 200K, so I'm still puzzled. 

I haven't yet used the UPX thing, so that wasn't it, tho it's something explore....
It works better if you plug it in.

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: Smaller executables
« Reply #3 on: May 16, 2019, 06:05:21 am »
there are a number of makeline text files in the directory /qb64/internal/c/
you could edit the appropriate makeline file adding -Os after g++
-Os means optimize for size
« Last Edit: May 16, 2019, 06:11:07 am by jack »

Offline Raven_Singularity

  • Forum Regular
  • Posts: 158
    • View Profile
Re: Smaller executables
« Reply #4 on: May 17, 2019, 04:09:43 am »
Here's some extra information on optimisation options for the g++ compiler:

Quote
Turning on optimization flags makes the compiler attempt to improve the performance and/or code size at the expense of compilation time and possibly the ability to debug the program.

The compiler performs optimization based on the knowledge it has of the program. Compiling multiple files at once to a single output file mode allows the compiler to use information gained from all of the files when compiling each of them.

Not all optimizations are controlled directly by a flag. Only optimizations that have a flag are listed in this section.

Most optimizations are only enabled if an -O level is set on the command line. Otherwise they are disabled, even if individual optimization flags are specified.

Depending on the target and how GCC was configured, a slightly different set of optimizations may be enabled at each -O level than those listed here. You can invoke GCC with `-Q --help=optimizers' to find out the exact set of optimizations that are enabled at each level. See Overall Options, for examples.

-O
-O1
    Optimize. Optimizing compilation takes somewhat more time, and a lot more memory for a large function.

    With -O, the compiler tries to reduce code size and execution time, without performing any optimizations that take a great deal of compilation time.

    -O turns on the following optimization flags:

              -fauto-inc-dec
              -fcompare-elim
              -fcprop-registers
              -fdce
              -fdefer-pop
              -fdelayed-branch
              -fdse
              -fguess-branch-probability
              -fif-conversion2
              -fif-conversion
              -fipa-pure-const
              -fipa-profile
              -fipa-reference
              -fmerge-constants
              -fsplit-wide-types
              -ftree-bit-ccp
              -ftree-builtin-call-dce
              -ftree-ccp
              -ftree-ch
              -ftree-copyrename
              -ftree-dce
              -ftree-dominator-opts
              -ftree-dse
              -ftree-forwprop
              -ftree-fre
              -ftree-phiprop
              -ftree-sra
              -ftree-pta
              -ftree-ter
              -funit-at-a-time
         

    -O also turns on -fomit-frame-pointer on machines where doing so does not interfere with debugging.
-O2
    Optimize even more. GCC performs nearly all supported optimizations that do not involve a space-speed tradeoff. As compared to -O, this option increases both compilation time and the performance of the generated code.

    -O2 turns on all optimization flags specified by -O. It also turns on the following optimization flags:

              -fthread-jumps
              -falign-functions  -falign-jumps
              -falign-loops  -falign-labels
              -fcaller-saves
              -fcrossjumping
              -fcse-follow-jumps  -fcse-skip-blocks
              -fdelete-null-pointer-checks
              -fdevirtualize
              -fexpensive-optimizations
              -fgcse  -fgcse-lm 
              -finline-small-functions
              -findirect-inlining
              -fipa-sra
              -foptimize-sibling-calls
              -fpartial-inlining
              -fpeephole2
              -fregmove
              -freorder-blocks  -freorder-functions
              -frerun-cse-after-loop 
              -fsched-interblock  -fsched-spec
              -fschedule-insns  -fschedule-insns2
              -fstrict-aliasing -fstrict-overflow
              -ftree-switch-conversion
              -ftree-pre
              -ftree-vrp
         

    Please note the warning under -fgcse about invoking -O2 on programs that use computed gotos.
-O3
    Optimize yet more. -O3 turns on all optimizations specified by -O2 and also turns on the -finline-functions, -funswitch-loops, -fpredictive-commoning, -fgcse-after-reload, -ftree-vectorize and -fipa-cp-clone options.
-O0
    Reduce compilation time and make debugging produce the expected results. This is the default.
-Os
    Optimize for size. -Os enables all -O2 optimizations that do not typically increase code size. It also performs further optimizations designed to reduce code size.

    -Os disables the following optimization flags:

              -falign-functions  -falign-jumps  -falign-loops
              -falign-labels  -freorder-blocks  -freorder-blocks-and-partition
              -fprefetch-loop-arrays  -ftree-vect-loop-version

-Ofast
    Disregard strict standards compliance. -Ofast enables all -O3 optimizations. It also enables optimizations that are not valid for all standard compliant programs. It turns on -ffast-math.

    If you use multiple -O options, with or without level numbers, the last such option is the one that is effective.


Edit:

UPX can be run on the executable after it is compiled by g++, it will further crush the executable down using in-place compression (almost no CPU/RAM/time overhead on execution).  That can reduce the executable size a further 30% or more.

« Last Edit: May 17, 2019, 04:14:08 am by Raven_Singularity »