9 ms·
One example I thought of is to use the ability to tap into exceptions being handled to audit for places where performance could be improved by swapping exceptio
by everforward 3y ago
One example I thought of is to use the ability to tap into exceptions being handled to audit for places where performance could be improved by swapping exceptions for sentinel values.
Iirc there's a significant performance penalty for raising exceptions. So you could tap into exceptions being handled to see something like "requests that fail validation raise an exception, and this happens often enough that we could get a performance boost by returning a sentinel value instead".
Another idea is that you might be able to use the conditional hooks to write a tool that can suggest re-ordering your if-elif-elif-else kind of statements so that the most common path is first, and prevent evaluating the other possibilities more often.
At a high level, it's just machinery for getting metadata about your code's runtime as part of the interpreter. You could probably write a lot of this as decorators, but because this is part of the interpreter it's decoupled from your frameworks/libraries/etc.