Speed up stubs suggestions by hauntsaninja · Pull Request #17965 · python/mypy · GitHub
Skip to content

Speed up stubs suggestions#17965

Merged
hauntsaninja merged 7 commits into
python:masterfrom
hauntsaninja:faster-suggest
Oct 16, 2024
Merged

Speed up stubs suggestions#17965
hauntsaninja merged 7 commits into
python:masterfrom
hauntsaninja:faster-suggest

Conversation

@hauntsaninja

@hauntsaninja hauntsaninja commented Oct 16, 2024

Copy link
Copy Markdown
Collaborator

See #17948
This is starting to show up on profiles

  • 1.01x faster on clean (below noise)
  • 1.02x faster on long
  • 1.02x faster on openai
  • 1.01x faster on openai incremental

I had a dumb bug that was preventing the optimisation for a while, I'll see if I can make it even faster. Currently it's a small improvement

We could also get rid of the legacy stuff in mypy 2.0

This is starting to show up on profiles, especially incremental ones
@hauntsaninja hauntsaninja marked this pull request as draft October 16, 2024 02:46
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@hauntsaninja hauntsaninja marked this pull request as ready for review October 16, 2024 05:13

@JukkaL JukkaL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks! Looks good, left some minor optional comments.

Comment thread mypy/stubinfo.py Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I wonder if module.split(".", 1)[0] would be faster.

Comment thread mypy/test/teststubinfo.py
assert stub_distribution_name("babel") == "types-babel"
assert stub_distribution_name("google.cloud.ndb") == "types-google-cloud-ndb"
assert stub_distribution_name("google.cloud.ndb.submodule") == "types-google-cloud-ndb"
assert stub_distribution_name("google.cloud.unknown") is None

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe also test good.protobuf, since it's a slightly different case as there are two packages under the google prefix?

Comment thread mypy/stubinfo.py Outdated
def approved_stub_package_exists(prefix: str) -> bool:
return is_legacy_bundled_package(prefix) or prefix in non_bundled_packages
def approved_stub_package_exists(module: str) -> bool:
components = module.split(".")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Again, it might be slightly faster to use module.split(".", 1)[0] to calculate prefix, and only do the full split in the body of the last if statement as needed.

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

@hauntsaninja hauntsaninja merged commit 1be3a8b into python:master Oct 16, 2024
@hauntsaninja hauntsaninja deleted the faster-suggest branch October 16, 2024 23:21
hauntsaninja added a commit that referenced this pull request Oct 20, 2024
See #17948
This is starting to show up on profiles

- 1.01x faster on clean (below noise)
- 1.02x faster on long
- 1.02x faster on openai
- 1.01x faster on openai incremental

I had a dumb bug that was preventing the optimisation for a while, I'll
see if I can make it even faster. Currently it's a small improvement

We could also get rid of the legacy stuff in mypy 2.0
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