gh-107674: Improve performance of `sys.settrace`
This PR is reverted in #116178 because of a refleak failure. The test was proved to be wrong(not useful anymore?) with main and was removed in #116687. So this PR is back!
There is a slight change compared to the original PR thanks to @brandtbucher - in RESUME_CHECK, we should not DEOPT when eval_breaker is different than version if we are tracing. If we are not tracing, that's fine, but if we are tracing, we shoud only check the events, not the code version - otherwise we will just specialize and deopt that RESUME instruction everytime we execute it.
This introduces an extra branch check in RESUME_CHECK, which I think is fine (a check is introduced to RESUME too). There are some techniques that we can use to slightly optimize the fast path (non-tracing) by checking the eval_breaker == version first then check tracing. I don't think that helps a lot and it would make code a bit harder to read, but I can try it if that's desired.
- Issue: gh-107674