Skip to content

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