Skip to content
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

[mypyc] Add primitive ops for dictionary methods #8742

Merged
merged 12 commits into from
May 6, 2020

Conversation

ilevkivskyi
Copy link
Member

@ilevkivskyi ilevkivskyi commented Apr 28, 2020

This covers both view and list versions (it looks like both are used relatively often, at least in mypy). This accompanies #8725 to account for cases where keys/values/items appear in non-loop contexts.

@ilevkivskyi
Copy link
Member Author

...and as usual Python 3.5 is totally busted. I will probably just disable this on Python 3.5. PR #8725 adds the corresponding CompilerOptions flag, I will just reuse it here.

@ilevkivskyi
Copy link
Member Author

@msullivan @JukkaL I switched to disabling the optimization for subclasses here too. Now tests pass on Python 3.5.

@JukkaL
Copy link
Collaborator

JukkaL commented May 6, 2020

I measured that this can make the ops at least 2x faster for small dictionaries. This is a great improvement!

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, and the performance improvement is also significant. Left some ideas about additional tests.

@@ -1035,14 +1035,17 @@ def u(x: int) -> int:
d.update(x=x)
return d['x']

def get_content(d: Dict[int, int]) -> Tuple[List[int], List[int], List[Tuple[int, int]]]:
return list(d.keys()), list(d.values()), list(d.items())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add also tests for the "plain" primitive ops that don't create a list, such as by doing set(d.keys())?

Might be worth testing dict subclasses as well.

@ilevkivskyi ilevkivskyi merged commit 2d06ba7 into python:master May 6, 2020
@ilevkivskyi ilevkivskyi deleted the dict-methods branch May 6, 2020 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants