Live data from Hacker News

Outsmarting the compiler: Short story about optimization

dpzmick.com

21–26 of 26 posts

Re: Outsmarting the compiler: Short story about optimization

#23
post #21
post #19

gcc warning: ISO C++ forbids zero-size array ‘payload’ [-Wpedantic] clang warning: flexible array members are a C99 feature [-Wc99-extensions] is this still the case?

Try compiling with c++11 turned on.

I used -std=c++14

Re: Outsmarting the compiler: Short story about optimization

#24
post #15
post #14

> Then, a bit later, we need to very quickly finish populating the structs. I am finding it extremely hard to envision a circumstance where this is a bottleneck for anything. Care to clarify the context? I also find the struct layout really odd; why not just move c? Your benchmarks are also probably broken; branch predictors use global state so will almost certainly predict fine the way you've used things. You need t…

I'll give that benchmark trick a try. Thanks for the feedback. For some additional context, these structs are packed wire-line protocol structs. In reality the padding bytes are full of other fun details.

The question for context is how this became something you want to optimise. It seems almost anything else you do with the values would cost more than the part you tried to optimise.

Re: Outsmarting the compiler: Short story about optimization

#25
post #24
post #15

Earlier quoted context omitted.

I'll give that benchmark trick a try. Thanks for the feedback. For some additional context, these structs are packed wire-line protocol structs. In reality the padding bytes are full of other fun details.

The question for context is how this became something you want to optimise. It seems almost anything else you do with the values would cost more than the part you tried to optimise.

Very little is done with these values in the fast path. The application in question is basically a smart proxy that performs a very minimal amount of formatting. Most of the code in the fast path is pretty linear so I was curious if there were any good way to keep this particular case conditional free.

But, you are right that it probably doesn't matter. The minimal benchmarking I did convinced us that there wouldn't be much of a cost. The code that actually ended up being committed to our project has the branch.

Post reply on HN