Repository navigation
Speed up import isal by not importing __future__ in the version file - #335
Merged
rhpvorderman merged 5 commits intoNov 18, 2026
Merged
Conversation
The default version file template of setuptools-scm 10, which isolated builds now get, starts with "from __future__ import annotations". __future__ is not a frozen module, so every "import isal" loaded it from disk unless another module had done so first. isal only uses __version__, and _version.pyi declares nothing else, so a one-line template now replaces the default. Under cachegrind, "import isal" runs 576K fewer instructions on Python 3.11 and 653K fewer on 3.14, about a third of what it costs on top of interpreter startup. Timed in the process on Linux, "import isal.isal_zlib" takes 0.13 ms less on 3.11 (776 to 646 us) and 0.21 ms less on 3.14 (944 to 736 us). Processes that have already imported __future__ see no change. isal._version no longer has version, version_tuple, commit_id and their dunder forms. Nothing in isal uses them.
rhpvorderman
left a comment
Collaborator
There was a problem hiding this comment.
I just checked. The from __future__ import annotations is no longer needed since python 3.9. So there is no need to keep that import in there. I do like to keep the rest of the version file though.
Downstream code can use version_tuple and commit_id from isal._version, for example to check for a feature. The template is now the default template of setuptools-scm 10 without "from __future__ import annotations", so the version file keeps version, version_tuple, commit_id and their dunder forms. Python 3.10 and later can evaluate its annotations without the import, and Python 3.14 does not evaluate them on import. The commit_id line needs scm_version.short_node, which setuptools-scm has had since 9.2.0. Older versions fail the build with an AttributeError, so the build now requires setuptools-scm 9.2 or later. _version.pyi declares all the variables, so type checkers accept them too. Timed in the process on Python 3.14, as the median of 300 interleaved runs, "import isal.isal_zlib" takes 267 us. It takes 327 us with the default template, and 262 us when the version file only sets __version__.
Testing this detail of the version file template is not needed.
ptweezy
force-pushed
the
minimal-version-file
branch
from
November 18, 2026 01:54
ba62f86 to
2f6552f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The default version file template of setuptools-scm 10, which isolated builds now use, starts with
from __future__ import annotations.__future__is not a frozen module, so everyimport isalloads it from disk unless another module already has. This PR setsversion_file_templateinpyproject.tomlto that default template without the__future__import. The generated file keepsversion,version_tuple,commit_idand their dunder forms. It only differs from the default in that line and in the first comment, which names setuptools-scm instead of vcs-versioning.Without the import, Python 3.11 to 3.13 evaluate annotations such as
tuple[int | str, ...]when the module is imported, which works from Python 3.10 on. Python 3.14 does not evaluate them on import.The
commit_idline usesscm_version.short_node, which setuptools-scm has had since 9.2.0. With 8.x the build fails withAttributeError: 'ScmVersion' object has no attribute 'short_node', sobuild-system.requiresnow asks forsetuptools-scm>=9.2. setuptools-scm 9.2.0 and 10.3.4 write the same file._version.pyinow declares all the variables, so type checkers accept them.Timed in the process on Linux with Python 3.14, as the median of 300 interleaved runs,
import isal.isal_zlibtakes 267 µs instead of 327 µs. A version file that only sets__version__takes 262 µs, so keeping the variables costs about 5 µs. A program that has already imported__future__saves nothing.tests/test_version.pychecks__version__againstimportlib.metadata. The test suite passes on this branch on Linux with CPython 3.14.Checklist