djberg96 (2603)

Optimization flags

I just noticed an interesting difference between Perl's ExtUtils::MakeMaker and Ruby's mkmf - Perl defaults to -O while Ruby defaults to -O2 (the optimization level).

I'm not sure how much of a difference this *really* makes - I haven't done any serious benchmarks, though I saw no difference between -O2 vs -O3 when I tested a Ruby module.

Is there any reason NOT to put 'OPTIMIZE => "-O2"' for extensions in your Makefile.PL? All the gcc manual says is that it might make debugging more difficult and use more memory during the build phase. Not much of an issue for the majority of extensions out there, I don't think.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
Without JavaScript enabled, you might want to
use the classic discussion system instead. If you login, you can remember this preference.

I'm confused then (bear with me - it happens often). According to the gcc docs, "-O" is its own option, separate from "-O0", which is the (factory) default setting. But then, I can't seem to figure out how to tell what the default optimization level is in the first place (assuming it's been changed from -O0).

You can check the installed man page for gcc and hope it's up to date. For OS X, -O and -O1 are the same, and it looks the same for my linux box, though whether that's true or not is something else entirely.

Which optimizations -O turns on for various optimization levels is potentially build and system dependent, just to add some fun into the mix. And, of course, GCC's optimizer gets slowly better over time, so even if the settings are identical you may get different runtimes depending on the version of GCC

It's probably all right most of the time. Most likely on well tested platforms like x86 Linux. But by the time you get on to the platforms where gcc is less well tested at all of it's optimsations, you can come across subtle bugs. At least, that's the impressionI get from the very conservative FreeBSD guys. They will not endorse compiling world or kernel with -O2, only -O.

Ultimately, it's really a user choice though, and not something that should be embedded in a Makefile. If you want all your CPAN d

MakeMaker is just following whatever is in your Config.pm which is whatever you decided the optimization level should be when you configured and installed Perl. If you took the default,then it comes from whatever configuration hints are available for your OS. Most these daysuse -O2 or -O3. Some, like OS X, choose -Os by default. Others (SCO, IRIX, AU/X) use -O toplay it safe.

And if you installed Perl from a vendor (Debian, Redhat, Sun, etc...) they could have changed the default, too.