Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Don't trust your compiler. Your code is only fast if you're lucky.

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



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!




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: