Compiling C libraries with -O3 in release

It would be great to use -O3 instead of -O2 for release builds for better performance. Is there a way to force this to happen? If not, +1 for either changing the default behavior or creating a way to force it.

You can force it using swift build -Xcc -O3. I don't have opinions on what should be the default though /cc @ddunbar @jrose

This option will not work for me because I want to create a library that will get built by third-party consumers, and I don't want to have to tell them to use -Xcc -O3. Plus, that would force their other dependencies to be compiled the same way

I think it's a reasonable request to have a mechanism to specify some CFLAGS, but for this particular case: have you actually measured it being beneficial for your library? -O2 or -Os is generally a better default than -O3, in that it actually results in better performance in most cases.

From my benchmarking, I'm not seeing an impact for any of the flags that rises above the noise (6% std. dev.) of the benchmarks. So, -O2 is fine

1 Like