Skip to content

Couple obvious optimizations for type aliases #8099

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

Merged
merged 2 commits into from
Dec 7, 2019

Conversation

ilevkivskyi
Copy link
Member

This PR:

  • Removes three unused slots
  • Makes recursivity test once per alias
  • Documents an existing optimization (accidentally made before)

The effect of this it at the limit of precision on my laptop, but it looks like this gives around 1% speed-up (for cold runs).

@ilevkivskyi ilevkivskyi requested a review from JukkaL December 6, 2019 14:13
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 good, just a few minor comments.

@@ -2755,6 +2755,7 @@ def __init__(self, target: 'mypy.types.Type', fullname: str, line: int, column:
self.alias_tvars = alias_tvars
self.no_args = no_args
self.normalized = normalized
self._is_recursive = None # type: Optional[bool]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add comment (mention that if non-None, this the cached value). Maybe also mention that this is manipulated by TypeAliasType, as otherwise a reader may be confused as not much is done here with this.

is_recursive = self.alias._is_recursive
if is_recursive is None:
is_recursive = self.expand_all_if_possible() is None
self.alias._is_recursive = is_recursive
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add comment (we cache the value as an optimization).

@ilevkivskyi ilevkivskyi merged commit e8ae122 into python:master Dec 7, 2019
@ilevkivskyi ilevkivskyi deleted the some-alias-speed branch December 7, 2019 14:22
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