-
Notifications
You must be signed in to change notification settings - Fork 267
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
@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) |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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
Thanks! |
## 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
This PR makes a few performance improvements:
_is_compatible(arch, glibc_version)
tag
variable directly into the yield, reducing memory allocation in case this is never used when_is_compatible(arch, glibc_version)
is false