# Optimization flags

**URL:** <https://www.ruby-forum.com/t/optimization-flags/244919>\
**Category:** NGINX\
**Created:** [July 8, 2016, 2:44pm UTC](https://www.ruby-forum.com/t/optimization-flags/244919 "2016-07-08T14:44:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [July 8, 2016, 2:44pm UTC](https://www.ruby-forum.com/t/optimization-flags/244919/1 "2016-07-08T14:44:47Z")

</div>

The default --with-cc-opt flags for Nginx are these:

\*–with-cc-opt=’-g -O2 -fstack-protector-strong -Wformat

> -Werror=format-security -Wp,-D\_FORTIFY\_SOURCE=2’\*

However I added more optimizations, which are against the standard:

\*–with-cc-opt=’-g -Ofast -march=native -ffast-math

> -fstack-protector-strong -Wformat -Werror=format-security  
> -Wp,-D\_FORTIFY\_SOURCE=2’\*

So far I don’t experience any bug, but I do have a higher benchmark:  
380-450 req/s compared to the original 290-310 req/s with cached  
Node/Express app on my laptop.

Is it safe to use -O3 or -Ofast flags with Nginx?

Is it possible to build Nginx with clang? If so, should I symlink it to  
gcc  
(I use Docker, this way gcc executable is trashed) or is there a way to  
define the compiler with a flag?

---

<div class="post-metadata">

**Author:** ![Lantos\_IstvSSn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e495f1/32.png) [@Lantos\_IstvSSn](https://www.ruby-forum.com/u/Lantos_IstvSSn)\
**Post date:** [July 8, 2016, 3:19pm UTC](https://www.ruby-forum.com/t/optimization-flags/244919/2 "2016-07-08T15:19:50Z")

</div>

Seems like --with-cc=clang flag is where I can define clang compiler. Is  
it  
safe to use with --with-cc-opt='-std=c11 …? I think clang uses C11  
anyway.

2016-07-08 14:44 GMT+02:00 Lantos István [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Lantos\_IstvSSn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e495f1/32.png) [@Lantos\_IstvSSn](https://www.ruby-forum.com/u/Lantos_IstvSSn)\
**Post date:** [July 8, 2016, 3:21pm UTC](https://www.ruby-forum.com/t/optimization-flags/244919/3 "2016-07-08T15:21:35Z")

</div>

On Friday 08 July 2016 14:44:00 Lantos Istvn wrote:

> > -Wp,-D\_FORTIFY\_SOURCE=2’\*
> 
> So far I don’t experience any bug, but I do have a higher benchmark:  
> 380-450 req/s compared to the original 290-310 req/s with cached  
> Node/Express app on my laptop.
> 
> Is it safe to use -O3 or -Ofast flags with Nginx?

Usually it is safe. You can run tests: [hg.nginx.org is decommissioned](http://hg.nginx.org/nginx-tests/)

> Is it possible to build Nginx with clang? If so, should I symlink it to gcc  
> (I use Docker, this way gcc executable is trashed) or is there a way to  
> define the compiler with a flag?

–with-cc=

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![Lantos\_IstvSSn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e495f1/32.png) [@Lantos\_IstvSSn](https://www.ruby-forum.com/u/Lantos_IstvSSn)\
**Post date:** [July 8, 2016, 11:10pm UTC](https://www.ruby-forum.com/t/optimization-flags/244919/4 "2016-07-08T23:10:34Z")

</div>

I made a non-scientific benchmark on my laptop with my project. Although  
jumping from -O2 to -Ofast giving me dramatic speed boost, it’s  
interesting  
to see that going from gcc-4.9 to clang-3.9, there’s no difference, just  
margin of error. The test is non-scientific, I worked on my PC at midday  
on  
raw pictures, lots of programs open, but still, those readings almost  
identical.

My verdict is there’s no reason to introduce clang into my Docker build,  
because doesn’t make any speed difference. Going from -O2 to -Ofast  
makes.  
290-310req/s vs 380-450 req/s.

2016-07-08 15:22 GMT+02:00 Lantos István [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Lantos\_IstvSSn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e495f1/32.png) [@Lantos\_IstvSSn](https://www.ruby-forum.com/u/Lantos_IstvSSn)\
**Post date:** [July 8, 2016, 3:22pm UTC](https://www.ruby-forum.com/t/optimization-flags/244919/5 "2016-07-08T15:22:45Z")

</div>

Thank You!

2016-07-08 15:20 GMT+02:00 Valentin V. Bartenev [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
