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

Fix small regression in subtype cache performance #5604

Merged
merged 8 commits into from
Sep 12, 2018

Conversation

ilevkivskyi
Copy link
Member

@ilevkivskyi ilevkivskyi commented Sep 11, 2018

Fixes #5514

The root cause is that #5474 added type_parameter_checker (a function) as one of the keys of subtype kinds. This function is a nested one, so in fact a new function was created on every call to is_subtype_ignoring_tvars() causing many thousands parasitic keys created in subtype caches. In addition there are two smaller things listed below.

The performance win is around 5%
This PR:

  • Moves the mentioned function to global scope, this causes only 6 subtype kinds present during self-check.
  • Prevents similar regressions in future by switching only boolean flags as subtype kind keys.
  • Removes two one liners that stay in a very hot code path (cache lookup is hit 140K times during self-check).
  • Avoids creation of empty sets on cache look-up, create them only when writing to cache.

Copy link
Collaborator

@Michael0x2a Michael0x2a left a comment

Choose a reason for hiding this comment

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

LGTM! I don't really have any feedback or nitpicks. I think this is good to merge once the tests pass.

@ilevkivskyi
Copy link
Member Author

I will cherry-pick this into release branch after merging.

@ilevkivskyi ilevkivskyi merged commit 70767bd into python:master Sep 12, 2018
@ilevkivskyi ilevkivskyi deleted the sub-cache-perf branch September 12, 2018 13:03
ilevkivskyi added a commit that referenced this pull request Sep 12, 2018
Fixes #5514

The root cause is that #5474 added `type_parameter_checker` (a function) as one of the keys of subtype kinds. This function is a nested one, so in fact a _new_ function was created on every call to `is_subtype_ignoring_tvars()` causing many thousands parasitic keys created in subtype caches. In addition there are two smaller things listed below.

The performance win is around 5%
This PR:
* Moves the mentioned function to global scope, this causes only 6 subtype kinds present during self-check.
* Prevents similar regressions in future by switching only boolean flags as subtype kind keys.
* Removes two one liners that stay in a very hot code path (cache lookup is hit 140K times during self-check).
* Avoids creation of empty sets on cache look-up, create them only when writing to cache.
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