-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[mypyc] Use PyList_Check for isinstance(obj, list) #19416
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
Conversation
mypyc/test-data/run-lists.test
Outdated
class list: | ||
pass | ||
|
||
def test() -> None: |
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 don't think this gets executed, since the test runner looks for a test_
prefix. Also, can you merge the new test cases under one [case ...]
and add multiple def test_...
methods for sub test cases? Each top-level test case has significant constant overhead, so having a few, bigger test cases makes the test suite run faster.
mypyc/test-data/run-lists.test
Outdated
|
||
[case testIsInstance] | ||
from copysubclass import subc | ||
def test() -> None: |
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.
Similar to my other comment about test_
prefix.
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.
Thanks for the updates! Looks good now.
Adding back a test for `next` with a list iterator as argument. Previously this test only checked if compilation succeeded so I have removed it in #19416, now it calls the test function and checks the result.
Follow-up to #19416 adding primitives for `isinstance(obj, type)` where type is built-in.
Added a primitive to translate
isinstance(obj, list)
toPyList_Check(obj)
instead ofPyObject_IsInstance(obj, type)
, as the former is faster. Similar primitives can be added for other built-in types, which I plan to do in next PRs.Using the above benchmark, execution time goes from ~1.4s to ~0.97s on my machine.