From 3ee8028bb471c9d74186c4e32a097f86f52ad540 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Wed, 28 May 2025 15:09:20 +0200 Subject: [PATCH] Improve performance of uv-python crate's manylinux submodule (#11131) ## 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 https://github.com/pypa/packaging/pull/869. Otherwise, I'm pretty confident this is a minor change that works the same --- crates/uv-python/python/packaging/_manylinux.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/crates/uv-python/python/packaging/_manylinux.py b/crates/uv-python/python/packaging/_manylinux.py index 3c3aa54cb..ea7125c76 100644 --- a/crates/uv-python/python/packaging/_manylinux.py +++ b/crates/uv-python/python/packaging/_manylinux.py @@ -232,7 +232,7 @@ def platform_tags(archs: Sequence[str]) -> Iterator[str]: if set(archs) & {"x86_64", "i686"}: # On x86/i686 also oldest glibc to be supported is (2, 5). too_old_glibc2 = _GLibCVersion(2, 4) - current_glibc = _GLibCVersion(*_get_glibc_version()) + current_glibc = _get_glibc_version() glibc_max_list = [current_glibc] # We can assume compatibility across glibc major versions. # https://sourceware.org/bugzilla/show_bug.cgi?id=24636 @@ -252,11 +252,8 @@ def platform_tags(archs: Sequence[str]) -> Iterator[str]: min_minor = -1 for glibc_minor in range(glibc_max.minor, min_minor, -1): glibc_version = _GLibCVersion(glibc_max.major, glibc_minor) - tag = "manylinux_{}_{}".format(*glibc_version) if _is_compatible(arch, glibc_version): - yield f"{tag}_{arch}" - # 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): + yield "manylinux_{}_{}_{}".format(*glibc_version, arch) + # Handle the legacy manylinux1, manylinux2010, manylinux2014 tags. + if legacy_tag := _LEGACY_MANYLINUX_MAP.get(glibc_version): yield f"{legacy_tag}_{arch}"