-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
gh-141858: Speed up Objects/tupleobject.c richcompare with early identity and length checks
#142027
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
base: main
Are you sure you want to change the base?
Changes from 8 commits
e834d59
956fef1
9ba8110
25d53eb
0813448
440a23a
c901539
3f824c0
c703f61
b1c53b2
0eae50d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -666,18 +666,24 @@ tuple_richcompare(PyObject *v, PyObject *w, int op) | |
| if (!PyTuple_Check(v) || !PyTuple_Check(w)) | ||
| Py_RETURN_NOTIMPLEMENTED; | ||
|
|
||
| if (v == w) { | ||
maurycy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Py_RETURN_RICHCOMPARE(0, 0, op); | ||
| } | ||
|
|
||
|
Comment on lines
+673
to
+676
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm aware of https://bugs.python.org/issue30907 but I think it was premature:
That said, even 25d53eb, without the identity check, is great (9f2a34a is The `pyperformance compare`:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Particularly: The `pyperformance compare`: |
||
| vt = (PyTupleObject *)v; | ||
| wt = (PyTupleObject *)w; | ||
|
|
||
| vlen = Py_SIZE(vt); | ||
| wlen = Py_SIZE(wt); | ||
|
|
||
| /* Note: the corresponding code for lists has an "early out" test | ||
| * here when op is EQ or NE and the lengths differ. That pays there, | ||
| * but Tim was unable to find any real code where EQ/NE tuple | ||
| * compares don't have the same length, so testing for it here would | ||
| * have cost without benefit. | ||
| */ | ||
| if (vlen != wlen) { | ||
| switch (op) { | ||
| case Py_EQ: | ||
| Py_RETURN_FALSE; | ||
| case Py_NE: | ||
| Py_RETURN_TRUE; | ||
| } | ||
| } | ||
|
|
||
| /* Search for the first index where items are different. | ||
| * Note that because tuples are immutable, it's safe to reuse | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.