3 ms·
[Knee jerk reaction] Be careful now. Be very careful. > Godbolt’s Law — if any single optimisation makes a routine run two or more times faster, then you’ve br
by repelsteeltje 3y ago
[Knee jerk reaction]
Be careful now. Be very careful.
> Godbolt’s Law — if any single optimisation makes a routine run two or more times faster, then you’ve broken the code.
<https://xania.org/200504/godbolt's-law https://xania.org/200504/godbolt's-law>
- eyelidlessness 3y agoIt’s a good law. Probably deserving of the term law in almost any circumstance, although I’ve definitely been “lucky” enough to find exceptions (ie optimizing horribly inefficient code where the optimizations really couldn’t have been premature at any point in prior development). Edit: even so, I’ve found the law holds often enough in exactly the same code. Then it’s a very good opportunity to expand test coverage.
- askiiart 3y agoIn a more idiotic vein, I accidentally added "RUN apt install rust-all" to the wrong Dockerfile. Removing that made the image 14x smaller.
- up2isomorphism 3y agoWhat nonsense is this. Someone did a big unnecessary big memcpy in a loop and you removed it and see 3x faster, how is this breaking the code?
- repelsteeltje 3y agoThe point of Matt Godbalt's "law" is that eventually you'll discover that the undocumented, mysterious memcpy wasn't unnecessary. Ie. It was a hacky resolution for a weird race condition edge case that couldn't be solved some other way without introducing some other, major regression. Off course, he doesn't mean to say you can never optimize to gain speed increases of > 2x. It's a hyperbole, build on his experience working with well written optimized time-critical software (think games, high volume/low latency trading), where on a good day you're happy to improve performance by 3%.