Lazarus

Using the Lazarus IDE => General => Topic started by: Josh on October 13, 2022, 05:30:06 pm

Title: Whole Program Optimization
Post by: Josh on October 13, 2022, 05:30:06 pm
Hi

On following the page for Lazarus Project Optimization
https://wiki.freepascal.org/Whole_Program_Optimization
I am getting odd results, so either its me, or something is missing.

I have set up 2 xtra build modes for my project pass 1 and pass 2, according to the above document.
After I compile with Pass 1 then Pass 2, my project is 56MB where as my project with just O2 Smart Link etc, comes out at just 15MB.

I suspect I have missed something. I do note that the fpc example has an extra step...

Any thoughts...

EDIT Just Noticed 4 digit posts..
Title: Re: Whole Program Optimization
Post by: BrunoK on October 13, 2022, 05:37:11 pm
Debug info ?
Title: Re: Whole Program Optimization
Post by: Josh on October 13, 2022, 05:51:09 pm
Hi

Pass 1, Pass 2, MyRelease Build modes do not have any debug info included, the Pass 1 and Pass 2 are copies of MyRelease Build mode with the addition of

Pass 1
Quote
-FWtempwindows.wpo
-CX
-XX
-Xs-
-OWDEVIRTCALLS
-OWOPTVMTS

Pass2
Quote
-Fwtempwindows.wpo
-CX
-XX
-Xs-
-OwDEVIRTCALLS
-OwOPTVMTS
Title: Re: Whole Program Optimization
Post by: marcov on October 13, 2022, 05:54:59 pm
The collection phase should not have stripping enabled according to the wiki?
Title: Re: Whole Program Optimization
Post by: Josh on October 13, 2022, 06:14:09 pm
Hi

I unchecked the strip in both Pass 1 and Pass 2, The exe is still 56MB

I created a Third Mode Release WPO Final and put
Quote
-Fwtempwindows.wpo
-CX
-XX
-OwDEVIRTCALLS
-OwOPTVMTS

When I run this after Pass 1 and Pass 2 My Exe is 13.6MB

Observation note, if your active build is pass 2, and you build many with pass 1and pass 2 in that order, because pass 2 is active mode, this is compiled first...
Title: Re: Whole Program Optimization
Post by: Fred vS on October 13, 2022, 06:39:20 pm
Hello.

Did you try with and without -B ?
Title: Re: Whole Program Optimization
Post by: Josh on October 13, 2022, 06:47:20 pm
Hi Fred

I cannot compile for all Build Modes, as I have Build for Win32,Win64,Carbon,Cocoa, each has a debug and release mode.
I was having issues with crosscompiling, so I have a Lazarus 32 Installation and Seperate 64 Installation, and The Mac Build options are for Actual Mac Installation on an old snowleopard system, and MacMini M1 on Monterey,
Title: Re: Whole Program Optimization
Post by: Fred vS on October 13, 2022, 06:55:41 pm
Hello Josh.

OK, i do also cross-compilation but I noted that, sometime, if compiling without -B parameter (build all) there was strange result.

So now, to avoid problems, I always use -B (even if it will rebuild all the units and take more time).
That said, maybe it is not related to your problem but, in case of...
Title: Re: Whole Program Optimization
Post by: Josh on October 13, 2022, 07:06:24 pm
Hi Fred,

I agree, before doing any 'Final Build' I go to Run/Clean Up and Build, and just delete the files. Then I build

I have Done this with this, but Pass 1 and Pass 2 endup with large file.
Title: Re: Whole Program Optimization
Post by: Fred vS on October 13, 2022, 07:13:17 pm
Not sure about your parameter -Xs- ( the - at end ).
I use this to strip:

Code: [Select]
-XX -CX -Xs
Title: Re: Whole Program Optimization
Post by: Josh on October 13, 2022, 07:17:59 pm
Hi Fred vS

The options are put in using,  Project Option, Custom Option, AllOptions, then scrolling and enabling the relevent paramters to add
 
Title: Re: Whole Program Optimization
Post by: Fred vS on October 13, 2022, 07:30:23 pm
Hello Josh.

I just try with a demo console program in Linux 64 bit:

Code: Pascal  [Select][+][-]
  1. fpc -XX -CX -Xs- test.pas

Result: 2.1 megas.

Then the same with -Xs (without - at end):

Code: Pascal  [Select][+][-]
  1. fpc -XX -CX -Xs test.pas

Result: 0.9 mega.
Title: Re: Whole Program Optimization
Post by: Fred vS on October 13, 2022, 07:49:17 pm
Hi Fred vS

The options are put in using,  Project Option, Custom Option, AllOptions, then scrolling and enabling the relevent paramters to add

Here with Lazarus 2.2.4 when selecting -Xs, it does not add a "-" at end.
Title: Re: Whole Program Optimization
Post by: Josh on October 13, 2022, 09:24:29 pm
Hi Fred vS,

Confirmed if I remove the trailing - from the -Xs-, then it works correctly. :) :)

Looks like the Wiki Needs Checking/Changing.
Where I got my info from https://wiki.freepascal.org/Whole_Program_Optimization
for both FPC and Lazarus
Title: Re: Whole Program Optimization
Post by: Fred vS on October 13, 2022, 09:29:32 pm
Looks like the Wiki Needs Checking/Changing.
Where I got my info from https://wiki.freepascal.org/Whole_Program_Optimization
for both FPC and Lazarus

Hum, indeed that picture:
https://wiki.freepascal.org/File:02_Linux_WPO_Pass1.png

Needs some work with LazPaint.  ;)

Title: Re: Whole Program Optimization
Post by: Josh on October 13, 2022, 09:33:32 pm
yes all 4 images, for *nix and windows, I assume the fpc snippets are not correct also..

Title: Re: Whole Program Optimization
Post by: Fred vS on October 13, 2022, 09:40:13 pm
I assume the fpc snippets are not correct also..

All those like this ?

Under "Compiler Options | Custom Options", add the Custom Options "-OWall -FWtemplinux.wpo -Xs- -CX"

But maybe we miss something, the "-" was wanted, I dont understand why ( it seems to me that adding "-" is equivalent to not add -Xs at all )
Title: Re: Whole Program Optimization
Post by: Fred vS on October 13, 2022, 09:54:43 pm
Hum, in fact I think the wiki is OK.
For the WPO phases (to collect the infos) the program must NOT be stripped.
And the  -Xs- parameter force to not use stripping, even if -Xs was added in the parameters.

Maybe.
 
Title: Re: Whole Program Optimization
Post by: Josh on October 13, 2022, 10:01:38 pm
That make sense for Pass 1 , but surely stripping is required for Pass 2
Title: Re: Whole Program Optimization
Post by: Fred vS on October 13, 2022, 10:09:06 pm
but surely stripping is required for Pass 2

In my case, I strip ( -Xs ) always the releases (but i know that it is at my own risk and this is not the best academical practice).  :-[
Title: Re: Whole Program Optimization
Post by: Josh on October 13, 2022, 10:26:26 pm
I also have the project option/debugging Strip Symbols From Execs enabled in release builds, so I assume -Xs- turns this off in Pass 1 (makes sure symbols are NOT stripped), but to reduce the exe size in Pass 2 it needs to be -Xs (Strip Symbols).

Of course I could be totally wrong.. %)
Title: Re: Whole Program Optimization
Post by: Fred vS on October 13, 2022, 10:37:37 pm
I also have the project option/debugging Strip Symbols From Execs enabled in release builds, so I assume -Xs- turns this off in Pass 1 (makes sure symbols are NOT stripped), but to reduce the exe size in Pass 2 it needs to be -Xs (Strip Symbols).

Of course I could be totally wrong.. %)

Quote
-Xs (Strip Symbols).

I have to check it, but for stripping, is it a external program that is used (strip), just after compilation or is it done by fpc himself  ?
[EDIT] It is done by a fpc tool strip.exe after compilation.
So it must be safe.

So yes, I dont see why -Xs- in Phase 2.
Title: Re: Whole Program Optimization
Post by: Josh on October 13, 2022, 11:06:41 pm
Hi
I renamed my strip.exe to oldstrip.exe in \fpc\bin\i386-win32 and fpcbootstrap(using fpcupdeluxe) no other strip on machine and strip in cmd prompt  says no file found so nothing in path , it still creates a small exe, so don't think strip is called.
Title: Re: Whole Program Optimization
Post by: Fred vS on October 13, 2022, 11:11:56 pm
Hi
I renamed my strip.exe to oldstrip.exe in \fpc\bin\i386-win32 and fpcbootstrap(using fpcupdeluxe) no other strip on machine and strip in cmd prompt  says no file found so nothing in path , it still creates a small exe, so don't think strip is called.

So, imho, there is a bug in the wiki for Phase 2.
Title: Re: Whole Program Optimization
Post by: Fred vS on October 13, 2022, 11:35:27 pm
About https://wiki.freepascal.org/Whole_Program_Optimization

After re-reading carefully the wiki, it seems to me that there is no error.
The mode WPA Pass 1 and WPA Pass 2 need -Xs-.

And should not be used for release.

IMHO there is missing the last chapter:
Building your release after WPO and there add the -Xs parameter.
TinyPortal © 2005-2018