8000 Improve performance in _manylinux.py by cthoyt · Pull Request #869 · pypa/packaging · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Improve performance in _manylinux.py #869

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
May 22, 2025
Merged

Improve performance in _manylinux.py #869

merged 2 commits into from
May 22, 2025

Conversation

cthoyt
Copy link
Contributor
@cthoyt cthoyt commented Jan 31, 2025

This PR makes a few performance improvements:

  1. Reduces the doubled call to _is_compatible(arch, glibc_version)
  2. Moves the assignment of the tag variable directly into the yield, reducing memory allocation in case this is never used when _is_compatible(arch, glibc_version) is false
  3. Uses an assignment expression for dictionary lookup

Copy link
Member
@uranusjr uranusjr left a comment

Choose a reason for hiding this comment

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

Nice

@cthoyt
Copy link
Contributor Author
cthoyt commented May 19, 2025

@pradyunsg thanks for the review, do you know the best way to advocate to get this PR merged that is respectful of the time/notification inbox of the maintainers?

if glibc_version in _LEGACY_MANYLINUX_MAP:
legacy_tag = _LEGACY_MANYLINUX_MAP[glibc_version]
if _is_compatible(arch, glibc_version):
yield "manylinux_{}_{}_{}".format(*glibc_version, arch)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this replaces the combination of tag = "manylinux_{}_{}".format(*glibc_version) and yield f"{tag}_{arch}" since these two string format operations are done in succession (without, imo, the intermediate name adding any useful context nor being reused anywhere)

# Handle the legacy manylinux1, manylinux2010, manylinux2014 tags.
if glibc_version in _LEGACY_MANYLINUX_MAP:
legacy_tag = _LEGACY_MANYLINUX_MAP[glibc_version]
if _is_compatible(arch, glibc_version):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the doubled call to _is_compatible is combine

@henryiii henryiii merged commit f89652b into pypa:main May 22, 2025
38 checks passed
@henryiii
Copy link
Contributor

Thanks!

@cthoyt cthoyt deleted the patch-2 branch May 22, 2025 22:03
konstin pushed a commit to astral-sh/uv that referenced this pull request May 28, 2025
## Summary

This PR makes a few performance improvements:

1. Reduces the need to unpack and repack a `_GLibCVersion` tuple
2. Reduces the doubled call to `_is_compatible(arch, glibc_version)`
3. Moves the assignment of the `tag` variable directly into the yield,
reducing memory allocation in case this is never used when
`_is_compatible(arch, glibc_version)` is false
4. Combines the check of the `glibc_version` being in
`_LEGACY_MANYLINUX_MAP` and the assignment to the variable together. I'm
not sure if this is actually better, but using the assignment expression
reduces this from 4 lines to 2

## Test Plan

I upstreamed these changes in
pypa/packaging#869. Otherwise, I'm pretty
confident this is a minor change that works the same
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.

4 participants
0