-
-
Notifications
You must be signed in to change notification settings - Fork 517
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
Use Cython directive binding=True to get signatures for cython methods #26254
Comments
comment:1
It seems this file https://github.com/ipython/ipython/blob/master/IPython/core/oinspect.py is responsible for this issue. For me, it would take some time to scrutinize what this does though. |
comment:2
A fix is to redefine |
comment:3
Replying to @kwankyu:
This is already done in |
comment:4
It turns out that the problem is with This problem is nothing to do with |
comment:5
We may just wait for future sage based on Python 3 with |
comment:7
I don't see the signature in a Python 3 build of Sage, either. |
comment:8
Replying to @jhpalmieri:
Right. I don't remember exactly what I meant in my last comment. Perhaps I expected Cython someday support the new signature module shipped with Python 3. Now I don't have any clear idea what should be done on what side. |
New commits:
|
Commit: |
Branch: public/26254 |
comment:10
Based on this discussion: and consulting: I made the last commit. Please checkout and try. |
Author: Kwankyu Lee |
comment:13
With your patch I get a bunch of doctest errors, of the kind
--- this is of course not a surpise, but it needs to be fixed on this ticket. Otherwise, I like it - e.g. notice how much more informative the error messages are. |
comment:14
This comes with the penalty of producing a wrapped object every time a method is accessed on a cython object. I suspect cythonized access avoids that, so it may be that in most scenarios this doesn't come with a performance penalty, but one should check carefully that sage doesn't rely on the situations where it does. Also, there is a reason why |
comment:15
Replying to @nbruin:
|
comment:16
An answer can be found here: and https://docs.python.org/3/howto/clinic.html Now it seems to me that cython should do a better job in making cythonized built-ins more introspectable. |
comment:17
To summarize the current situation, there are two options: Option 1: We accept the current patch, which turns on cython directive "binding=True" so that all cythonized methods become bound methods that already support the inspect.signature module well. If we take this path, then there is nothing for us to do except fixing a few doctests. Option 2: We wait for upstream cython fixes that will make all cythonized built-in methods properly support the inspect.signature module. This is the path that standard built-in methods follow. We don't know when the upstream fix would be available. Please give your preference and why. |
comment:19
To go with option 1, we need benchmarking results on whether it affects the performance a lot. |
comment:20
Replying to @dimpase:
If it affects any bit of the runtime performance in other aspect than introspection, then option 1 should be discarded. I think this should be decided not by experiments but analysis of how python and cython works. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
This comment has been minimized.
This comment has been minimized.
comment:130
Reported upstream: Preliminary timings there suggest the problem disappears with cython 3. So it would be instructive to check if the problem above persists in sage with an upgraded cython. If not, then we can just close this ticket and not do anything! |
comment:131
Thanks for the report. It would be interesting to see a real-world nontrivial (unlike |
comment:132
With Cython 3.0.0a11 it looks like "Binding" performs uniformly better. So I think we should wait for Cython 3 to come out and when we transition we can close this ticket, because the default changes there anyway. |
comment:133
Replying to Nils Bruin:
That's good news!
Except one line that changes the default, the other changes of this ticket (doctest fixes and adding |
comment:134
I looked at the upstream discussion. They say "Binding" is faster than "Unbinding"! That is almost unbelievably good news :) Then it means that adding If that is really true, then we can close this ticket and merge the commit for fixing doctest failures to the Cython 3 ticket. |
comment:135
Are there any news when Cython 3 will finally be released? If not, in light of the finding above that the bindings don't lead to (serious) performance decreases in "real life" even with cython 0.2x, I would suggest to merge this ticket without the manual |
comment:136
Replying to Tobias Diez:
It seems to go in beta status soon.
+1 from me. But I doubt if we could agree on this. If there is a disagreement, we cannot help but go to the way Nils suggested. |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
comment:138
Peeled off the commit of adding |
comment:139
I'd say wait for Cython 3 and, in the mean time, use 0c78cdf for development work if you're testing for the consequences of In any case, the branch here as it is shouldn't be merged: its net effect is an addition of 1 line (which can be reverted when cython 3 is merged). Rebase the 0c78cdf branch instead (or perhaps just force push it to the ticket) There's no need to pollute the change history with an incredible amount of line-addition-then-removal changes. |
comment:140
Replying to Nils Bruin:
Did you see comment:138 and the latest branch? It contains changes that will be necessary also for Cython 3. |
comment:141
Replying to Kwankyu Lee:
OK, sorry. It looks like you already cleaned up the branch (I now see the last push was indeed a "forced push"). Yes, this branch is fine then, but due to performance ramifications I think we should still wait until we're ready to upgrade to Cython 3 . Note that the cython folk pointed to cython/cython#4735 which may be affecting our performance with Python 3.10+ . It may be extra reason to upgrade to Cython 3. I don't know if upgrading to an "alpha" is warranted. Apparently :
So ... less forever until we can upgrade to a released Cython 3! |
comment:142
Replying to Nils Bruin:
Well, this was comment is already more than half a year old. The most recent comment about a beta of Cython 3 that I could find is cython/cython#4022 (comment), which is also 5 months old with no update since. Taking into account that the upgrade from v0.2x to v3 in Sage is also non-trivial (#29863), I would be surprised if Cython 3 will be fully supported in sage in the next few months. |
comment:143
This ticket is blocking other tickets (#27578, #30884, #31309, ...) for documentation improvement because of cython methods behaving differently with python methods. We may endure slight performance degradation (which, I think, no one will notice in real computing life) to enjoy conveniences brought by this ticket and allow progress of the mentioned tickets, in the meantime we wait for Cython 3 to arrive. |
In requests for help for cythonized built-in methods, the signature of the method is not shown, unlike normal python methods. For an example,
To fix this, we set Cython directive
binding=True
. Thus we buyfor slight performance degradation due to increased overhead cost of calling cython methods.
Related tickets: #19100, #20860, #18192
Depends on #32509
Depends on #33864
CC: @jdemeyer @tscrim @mkoeppe
Component: user interface
Author: Kwankyu Lee, Tobias Diez
Branch/Commit: public/26254 @
326f19c
Reviewer: Tobias Diez, ...
Issue created by migration from https://trac.sagemath.org/ticket/26254
The text was updated successfully, but these errors were encountered: