⚡️ Speed up function _have_compatible_abi by 564%
#3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📄 564% (5.64x) speedup for
_have_compatible_abiinsrc/packaging/_manylinux.py⏱️ Runtime :
11.3 microseconds→1.71 microsecondss(best of250runs)📝 Explanation and details
The optimization achieves a 563% speedup through three key changes that reduce computational overhead in architecture compatibility checking:
1. Module-level
frozensetfor allowed architecturesallowed_archsfrom a per-callsetconstruction to a module-level_ALLOWED_ARCHSfrozensetany()2. Early return pattern in ELF validation functions
andconditions with immediateif/return Falsestatements in_is_linux_armhfand_is_linux_i6863. Single-pass architecture scanning
any()generator) to oneforloop that returns immediately on first matcharchssequenceImpact on hot path usage: The
platform_tags()function calls_have_compatible_abiat the start of manylinux tag generation - a critical path for Python package installation. The optimization is particularly beneficial for:The optimized version maintains identical behavior while reducing both memory allocations and CPU cycles, making it especially valuable in packaging workflows where this function may be called repeatedly.
✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
🔎 Concolic Coverage Tests and Runtime
codeflash_concolic_quk6vk0y/tmprk8af1vi/test_concolic_coverage.py::test__have_compatible_abicodeflash_concolic_quk6vk0y/tmprk8af1vi/test_concolic_coverage.py::test__have_compatible_abi_2codeflash_concolic_quk6vk0y/tmprk8af1vi/test_concolic_coverage.py::test__have_compatible_abi_3To edit these changes
git checkout codeflash/optimize-_have_compatible_abi-miebhkz1and push.