Hi all, > On May 1, 2025, at 09:29, Levi Morrison <levi.morri...@datadoghq.com> wrote: > > On Tue, Apr 29, 2025 at 9:48 AM Paul M. Jones <pmjo...@pmjones.io> wrote: >> >> >> >>> On Apr 27, 2025, at 07:26, Niels Dossche <dossche.ni...@gmail.com> wrote: >>> >>> Regarding performance however, rather than introducing yet another >>> completely new concept to do almost the same thing, why not try to improve >>> exception performance instead? >>> >>> I just opened a PR that makes instantiating exceptions much much faster, >>> and this is only after like 15 mins of work. I'm sure there's even more to >>> gain. >> >> I mean, squeeze out gains where you can where the effort:reward ratio is >> good, but the following is a naive but representative result on an MacBook >> M3 Pro: >> >> ``` >> return false 100000 times = 0.075289011001587 >> throw exception 100000 times = 0.11530804634094 >> ``` >> >> Do we consider a difference of 0.075/100000s vs 0.115/100000s that big a >> deal when compared to (e.g.) establishing a database connection? > > The first part, the 0.075 vs 0.115... yeah, we care. That's 50% > slower.
(/me nods along) A 50% increase in execution time, but a 50% increase in things that when all combined take up (e.g.) only 0.01% of the total execution time -- is *that* something we care about? And "care about" relative to what else in comparison? Something like a starting a database connection might incur a much greater penalty, drowning out the exception penalty in total execution time. But then again ... > But the thing is, the math with exceptions is kind of [un]knowable > because one of the key aspects of its cost is walking the call stack. > How deep is the call stack going to be when a given library throws an > exception? You don't really know. [edited to include your note about the typo] ... yeah, that makes it tough to determine how much of a penalty there might be. How can we quantify that, if at all? In any case, if there are performance gains to be squeezed out of the existing exceptions model (especially at a good effort:reward ratio) then of course that's something to pursue. -- pmj