take control of exception object creation
The idea of this PR is to move exception creation out of the Python interpreter (where we can't control it, e.g. all the special cases in #4412), into our own code.
I think this would pave the way for optimisations and maybe relates to #4584 and #4413.
Having started on this, I think for 0.23 it's going to be simpler to just introduce some locking inside PyErr, however I would like to revisit this in the future as I think it will be a positive step. So for now I'm just pushing to see impact on benchmarks & tests, and so I don't forget it.
CodSpeed Performance Report
Merging #4669 will degrade performances by 10.37%
Comparing davidhewitt:create-exception-objects (929056f) with main (f74d374)
Summary
❌ 1 regression
✅ 80 untouched
:warning: Please fix the performance issues or acknowledge them on CodSpeed.
Benchmarks breakdown
| Benchmark | BASE |
HEAD |
Change | |
|---|---|---|---|---|
| ❌ | err_new_restore_and_fetch |
7.7 µs | 8.6 µs | -10.37% |