Hacker News
points by hinkley 2 days ago | 0 comments
One of the tricks here is to treat the happy path as a quasi-invariant and leave a guard that branches to slow code if the invariant didn’t hold.

I saw this presented as new tech at either OOPSLA or OSCon almost exactly 20 years ago.

CPU branch prediction is still pretty good even with the loss of function in recent years.

[–] Sesse__ 2 days ago
That works fine as long as nobody actually uses the unhappy path. If major libraries and frameworks do it all the time, you lose. So there is a certain aspect of culture outside what the language itself is capable of doing.
[–] hinkley 15 hours ago
As cpburns2009 says, the benefit of inlining code (which this technique often applies to) is that you make copies at multiple call sites and so they don’t have to share the same hottest branch.
[–] cpburns2009 1 day ago
If there's common real world paths that need to be supported, you can tailor optimizations to target those uses cases.