Repository navigation
⚡ perf(startup): defer pathlib loading - #228
Merged
Merged
Conversation
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 pre-commit-uv startup hook runs when Python starts, including processes that never run pre-commit. On Python 3.15, a paired 60-run benchmark of interpreter startup fell from 11.8 to 10.1 ms and peak memory from 11.5 to 10.8 MiB. Python 3.14 showed no material change.
The startup hook still checks whether the process is running pre-commit. Processes that do not run pre-commit skip the environment health check, so they no longer load
pathlibthrough this hook. Lifeguard found no lazy-import incompatibility in this module, and flake8-lazy identifiedpathlibas eligible.Benchmarks
Each block is one paired 60-run hyperfine invocation with
--warmup 5 --metrics time_wall_clock:ms,memory_peak_resident:MiB. Both commands used the same tox interpreter and dependencies, withPYTHONPATHselecting the merge-base or PR source tree. The direct module import uses-Sto isolate the hook from site initialization; the startup workload uses normal site initialization and executespython -c pass.Python 3.15
Interpreter startup with the
.pthhookDirect hook import (
python -S -c 'import pre_commit_uv._pre_commit_patch')Python 3.14
Interpreter startup with the
.pthhookDirect hook import (
python -S -c 'import pre_commit_uv._pre_commit_patch')Import profile
These Python 3.15 diagrams come from
python -X importtime -c passand tuna.pathlibappears in the startup hook's import tree before the change and is absent afterward.Before
After