-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
gh-91603: Speed up UnionType instantiation (alt) #91955
gh-91603: Speed up UnionType instantiation (alt) #91955
Conversation
Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
The new code is even shorter than the old one!
|
@serhiy-storchaka Just compare performance with my version. It's almost identical:
Benchmark hidden because not significant (3): (int | float) | list, (int | float) | (list | set), (float | set) | int | int | (float | list) |
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.
LGTM
I am not surprised because it is the same algorithm. "type | type" may be slightly slower because the code is more general, but it is a honest price for simpler code. On other hand, my code avoid creation a new tuple and a new UnionType object if possible, so it is expected that cases like I was skeptical about advisability of such optimization at all, but if it also reduces the size of the code I have no doubts. |
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.
Looks mostly good, but I have a question about refcounts.
if (args == NULL) { | ||
return NULL; | ||
if (*obj == Py_None) { | ||
*obj = (PyObject *)&_PyNone_Type; |
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.
Don't we need to INCREF here?
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, it is a borrowed reference.
🤖 New build scheduled with the buildbot fleet by @JelleZijlstra for commit a4badbc 🤖 If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again. |
Co-authored-by: Yurii Karabas 1998uriyyo@gmail.com
It is a rewriting of #91865.
Closes #91603.