Hacker News new | ask | show | jobs
by chrka 26 days ago
Don't trust your compiler. Your code is only fast if you're lucky.

https://tiki.li/blog/lucky_code.html

2 comments

I agree you can't trust your compiler, but you can control its behavior more reliably with __builtin_expect_with_probability

https://github.com/protocolbuffers/protobuf/commit/9f29f02a3...

that's a nice example. on my M4, i measured 3.4s vs. 0.42s. honestly surprised there's ~10x improvement to be found.

as you've pointed out, you've literally micro-optimised this - isn't this what you'd expect? :)

But what is the resulting assembly? I would assume completely different!