-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disable CYTHON_FAST_PYCALL on Py3.10 (0.29.x) #4735
Conversation
It causes issues while profiling or debugging where global variables can end up inadvertently changed. Fixes cython#4609
// On Python 3.10 it causes issues when used while profiling/debugging | ||
#define CYTHON_FAST_PYCALL (PY_VERSION_HEX < 0x030A0000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this perhaps be guarded with a debug-flag for python 3.10 to not regress performance in release builds?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Unfortunately it's Python-level debugging (i.e using sys.settrace
) that causes the problem so it needs applying generally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if the difference shows up in benchmarks?
@mattip I made a microbenchmark to try to measure this:
(I did also try a few variations with calling Representative results are:
To be honest I think my laptop is throttling itself too quickly to be really useful as a benchmark. However, I'm pretty confident that it won't cause a dramatic performance regression though. Feel free to investigate more yourself if it's something you're worried about though - I'm sure I haven't covered every case! |
I was recently asked what the performance difference is between the Limited API and CPython-optimised Cython, and had no answer. I then tried it with a simple caching example that uses ints, dicts and lists, and got a bit more than a 10% slowdown for the Limited API case. So, there are visible differences in the tricks that Cython pulls in the C-API, but in the end, these tricks have to add up to reach that difference, and are obviously highly use case specific. Disabling one of them should usually have a small effect in most cases, unless your code really depends on it. That said – if you want better performance, use Cython 3. If you value extreme language stability instead, stay with Cython 0.29.x for now. But be aware that maintenance for 0.29.x will probably end soon after Cython 3.0 is out. And that won't take as forever as it seemed for the last few years. |
Unfortunately, I somewhat expect the number of people running into this may skyrocket soon due to Python 3.10 getting more prelevant. So the packages using Cython should do bug-fix releases soon, ideally with this patch included. Can we make sure the next bug-fix release happens soonish? |
At this point, I think this is the last thing that would be nice to have a for a new NumPy release. I suppose, we could try to work-around it in NumPy, but it would be more convenient to have a release. As far as I can tell, all issues marked for |
It causes issues while profiling or debugging where global
variables can end up inadvertently changed.
Test largely copied from @seberg's reproducer
Fixes #4609