feat(debug-statements): implement builtin hook #886
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.
Description
Following discussion in #880 and initial bug report in #872 (where found prek slower than pre-commit for the
debug-statementshook in particular, which can be fixed by giving it a Rust port), this PR contributes such a "fast path" hook.This is a popular hook with 5,000+ repos using it on grep.app
Like #884 this one uses the
ruff_python_parsercrate from ruff to parse the AST and then its closely related crateruff_python_astto access nodes.ruff_python_parseralone in thecheck-asthook PR in feat(check-ast): implement builtin hook #884)Binary Size Change
+8.75% (.text: 16.0 MiB → 17.4 MiB)
Demo
Taking the top hit on grep.app, wandb/wandb
and running the latest release of prek and pre-commit, the
debug-statementshook runs 26% slower than pre-commit's:After installing this local feature branch, it runs 2x as fast 🎉
louis 🌟 ~/tmp/wandb $ prek run -a --verbose check-toml...............................................................Passed - hook id: check-toml - duration: 0.00s debug-statements.........................................................Passed - hook id: debug-statements - duration: 0.10s