Recent

Author Topic: About optimizations  (Read 4127 times)

lainz

  • Guest
About optimizations
« on: February 23, 2013, 04:00:49 am »
Hi, I recently noticed that FPC has optimizations, and those can be set from the Lazarus IDE in Project Options, Package Options and IDE Build Modes.

My question is: Which are really useful for improving speed and reducing size?

For example, I can set:

- Project Options: Optimizations Level 3, remove debug and strip symbols from exe, smart linking, keep certain variables in registers.

- Package: Optimizations Level 3, remove debug, keep certain variables in registers.

- Lazarus IDE: compile as Optimized IDE (Optimizations Level 2). Also we can set the options we want (for example, the same as Project Options).

In the IDE build modes there's a place for Packages in the 'Information' tab and it says 'Additional compiler info inherited from packages' What this means?

If I set optimizations for each package size will reduce? (FCL, LCL, LCLBase)..? Or the compiler build with the same as Lazarus?
----

(some of the above things I've seen on the wiki, I've tryed and here is the result)

What I've noticed:

- executable size goes down when I set strip symbols from executable.
- executable size goes down when I set Lazarus Build: Optimized IDE.

Things that I don't know how to measure: speed optimization. How I can notice if the program is faster?

Leledumbo

  • Hero Member
  • *****
  • Posts: 8112
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: About optimizations
« Reply #1 on: February 23, 2013, 06:14:42 am »
Quote
Which are really useful for improving speed and reducing size?
You can't really have both, choose one: speed or size. -Os is for size, the other -O is mostly speed, but there are some that can also have side effect or uncertain effect (e.g. -O4).
Quote
In the IDE build modes there's a place for Packages in the 'Information' tab and it says 'Additional compiler info inherited from packages' What this means?
Additional compiler options that will be passed to compiler from packages you install, mostly -Fu.
Quote
If I set optimizations for each package size will reduce? (FCL, LCL, LCLBase)..? Or the compiler build with the same as Lazarus?
Yes
Quote
Things that I don't know how to measure: speed optimization. How I can notice if the program is faster?
Benchmark it, simply using timer is enough. Note that this won't be noticable unless your program does heavy calculation. So the effect can be seen faster in a microbenchmark (benchmark that executes several programs one by one, each containing single functionality). Other easy way is to 'feel it'.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5713
    • wiki
Re: About optimizations
« Reply #2 on: February 23, 2013, 02:25:16 pm »
Hi, I recently noticed that FPC has optimizations, and those can be set from the Lazarus IDE in Project Options, Package Options and IDE Build Modes.

My question is: Which are really useful for improving speed and reducing size?

For example, I can set:

- Project Options: Optimizations Level 3, remove debug and strip symbols from exe, smart linking, keep certain variables in registers.

- Package: Optimizations Level 3, remove debug, keep certain variables in registers.

- Lazarus IDE: compile as Optimized IDE (Optimizations Level 2). Also we can set the options we want (for example, the same as Project Options).

- Project options apply to the files in your unit directory (unit1.pas), but not the packages, like LCL

- Package options apply, to whatever unit belong to that packages.
--- Packages have a "usage" section, and you can put options (as command line switches "-O2"), in there ("Custom" memo), then they apply to other packages, IF the other packages uses/depends on this. "LCL" uses "FCL" => if FCL has -O2 in Usage, then LCL uses that too.

- Menu Tools, configure build Lazarus: Applies to how the IDE is build. (Similar to project)
IT does affect "SOME, but NOT all" packages. This is concrolled by a package using $(IDEBuildOptions) in its "custom" options ("Other" in the Tree)

         
Quote
In the IDE build modes there's a place for Packages in the 'Information' tab and it says 'Additional compiler info inherited from packages' What this means?
       

 If a package, has options that will be used by the project... E.g. the project must include the Path of each package.

It shows options affecting the IDE/project units. The units in the package are build according to the package's options.

Put something into a packages "Usage" setting, and it should show up.

     
Quote
If I set optimizations for each package size will reduce? (FCL, LCL, LCLBase)..? Or the compiler build with the same as Lazarus?
         
You need to set for each package.

Or put -O2  and other into FCL usage (almost all packages use FCL).  However setting -O2 and others, READ ABOUT DEBUGGING. You will run into trouble.

Quote

What I've noticed:

- executable size goes down when I set strip symbols from executable.
- executable size goes down when I set Lazarus Build: Optimized IDE.
       

strip affects debug info. You always want it off when building releases, but need it when debugging. Debugger will also NOT work, if you have optimization on. SO if you put that global for all packages, you can not debug inside packages, and if the global option happens to affect your project, then debugging will not work (you will see wrong values, if you look at what value a variable has)

There are "Build modes" so you can switch many settings at once. There is some info on the wiki, but maybe some one else can explain more.

       
Quote

Things that I don't know how to measure: speed optimization. How I can notice if the program is faster?

Use a profiler (valgrind on linux), There is fpprofiler: google.
On Windows profiling is hard...

Then again, if you do not notice you may not need it.

You can also put the code into a loop, and run it 100000 times.
Mind of course that the execution time also depends, on what else your PC does at the time. SO it will vary anyway.

Also speed is archived by choosing the right algorithm. e.g on a sorted list, do a binary search, instead of going through all elements of a list...



Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5713
    • wiki
Re: About optimizations
« Reply #3 on: February 23, 2013, 02:30:57 pm »
Btw, some options only make sense in the project (or IDE)

- strip: will always strip the resulting exe. So info from packages is also stripped.

- smartlink, affects the resulting eke too.
yet packages must have "smart linkable"

- and some settings are better kept in sync. e.g if you choose debug info type (dwarf/stabs), and you also debug inside packages, then you better set it to the same in all places where you use it.

lainz

  • Guest
Re: About optimizations
« Reply #4 on: February 23, 2013, 06:22:41 pm »
 ;) Thanks, is clear for me now.