Remove unnecessary clones#2082
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR removes a few unnecessary .clone() calls, relying on ownership moves where values aren’t reused, to simplify code and avoid extra allocations.
Changes:
- Removed a redundant clone of
toolchain_pathin Rust version tests. - Removed a redundant clone of
range_reqin Python version tests. - Removed a redundant clone when reading
default_install_hook_typesfrom loaded config in the install CLI.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/prek/src/languages/rust/version.rs | Simplifies test setup by moving toolchain_path instead of cloning. |
| crates/prek/src/languages/python/version.rs | Simplifies test by moving range_req into the request instead of cloning. |
| crates/prek/src/cli/install.rs | Avoids cloning hook type defaults by moving the option value out of cfg. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2082 +/- ##
==========================================
- Coverage 92.35% 92.32% -0.03%
==========================================
Files 119 119
Lines 24328 24326 -2
==========================================
- Hits 22468 22459 -9
- Misses 1860 1867 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
c61033b to
daa4483
Compare
📦 Cargo Bloat ComparisonBinary size change: -0.76% (26.3 MiB → 26.1 MiB) Expand for cargo-bloat outputHead Branch ResultsBase Branch Results |
⚡️ Hyperfine BenchmarksSummary: 0 regressions, 0 improvements above the 10% threshold. Environment
CLI CommandsBenchmarking basic commands in the main repo:
|
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base --version |
2.3 ± 0.1 | 2.1 | 2.9 | 1.02 ± 0.06 |
prek-head --version |
2.3 ± 0.1 | 2.1 | 2.5 | 1.00 |
prek list
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base list |
9.4 ± 0.2 | 9.0 | 10.0 | 1.02 ± 0.04 |
prek-head list |
9.2 ± 0.3 | 8.8 | 10.8 | 1.00 |
prek validate-config .pre-commit-config.yaml
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base validate-config .pre-commit-config.yaml |
3.3 ± 0.1 | 3.1 | 3.6 | 1.07 ± 0.07 |
prek-head validate-config .pre-commit-config.yaml |
3.1 ± 0.2 | 2.9 | 4.3 | 1.00 |
prek sample-config
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base sample-config |
2.6 ± 0.1 | 2.5 | 2.7 | 1.03 ± 0.04 |
prek-head sample-config |
2.5 ± 0.1 | 2.4 | 2.8 | 1.00 |
Cold vs Warm Runs
Comparing first run (cold) vs subsequent runs (warm cache):
prek run --all-files (cold - no cache)
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run --all-files |
142.1 ± 2.6 | 139.1 | 146.3 | 1.00 |
prek-head run --all-files |
142.9 ± 2.6 | 139.7 | 148.2 | 1.01 ± 0.03 |
prek run --all-files (warm - with cache)
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run --all-files |
144.0 ± 3.5 | 139.2 | 149.8 | 1.00 |
prek-head run --all-files |
145.4 ± 3.3 | 137.7 | 151.1 | 1.01 ± 0.03 |
Full Hook Suite
Running the builtin hook suite on the benchmark workspace:
prek run --all-files (full builtin hook suite)
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run --all-files |
145.3 ± 3.7 | 138.3 | 151.2 | 1.01 ± 0.04 |
prek-head run --all-files |
143.7 ± 4.2 | 138.0 | 154.4 | 1.00 |
Individual Hook Performance
Benchmarking each hook individually on the test repo:
prek run trailing-whitespace --all-files
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run trailing-whitespace --all-files |
22.3 ± 2.0 | 20.7 | 30.6 | 1.05 ± 0.10 |
prek-head run trailing-whitespace --all-files |
21.2 ± 0.5 | 20.1 | 22.4 | 1.00 |
prek run end-of-file-fixer --all-files
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run end-of-file-fixer --all-files |
27.6 ± 2.2 | 24.4 | 32.6 | 1.00 |
prek-head run end-of-file-fixer --all-files |
28.1 ± 2.5 | 24.7 | 32.6 | 1.02 ± 0.12 |
prek run check-json --all-files
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run check-json --all-files |
12.4 ± 0.3 | 11.8 | 13.0 | 1.06 ± 0.05 |
prek-head run check-json --all-files |
11.7 ± 0.5 | 10.9 | 12.4 | 1.00 |
prek run check-yaml --all-files
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run check-yaml --all-files |
11.4 ± 0.3 | 11.1 | 12.0 | 1.00 ± 0.03 |
prek-head run check-yaml --all-files |
11.4 ± 0.3 | 11.0 | 12.0 | 1.00 |
prek run check-toml --all-files
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run check-toml --all-files |
11.4 ± 0.3 | 11.0 | 12.3 | 1.00 ± 0.04 |
prek-head run check-toml --all-files |
11.4 ± 0.3 | 10.9 | 12.3 | 1.00 |
prek run check-xml --all-files
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run check-xml --all-files |
11.4 ± 0.2 | 11.0 | 11.8 | 1.00 ± 0.03 |
prek-head run check-xml --all-files |
11.4 ± 0.3 | 10.9 | 12.0 | 1.00 |
prek run detect-private-key --all-files
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run detect-private-key --all-files |
18.3 ± 1.3 | 16.0 | 20.9 | 1.01 ± 0.11 |
prek-head run detect-private-key --all-files |
18.1 ± 1.4 | 15.9 | 21.6 | 1.00 |
prek run fix-byte-order-marker --all-files
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run fix-byte-order-marker --all-files |
23.1 ± 1.9 | 20.1 | 26.7 | 1.00 |
prek-head run fix-byte-order-marker --all-files |
23.1 ± 1.9 | 19.7 | 25.7 | 1.00 ± 0.12 |
Installation Performance
Benchmarking hook installation (fast path hooks skip Python setup):
prek install-hooks (cold - no cache)
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base install-hooks |
4.8 ± 0.1 | 4.8 | 5.0 | 1.02 ± 0.03 |
prek-head install-hooks |
4.8 ± 0.1 | 4.6 | 4.9 | 1.00 |
prek install-hooks (warm - with cache)
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base install-hooks |
4.6 ± 0.1 | 4.5 | 4.7 | 1.02 ± 0.03 |
prek-head install-hooks |
4.6 ± 0.1 | 4.4 | 4.7 | 1.00 |
File Filtering/Scoping Performance
Testing different file selection modes:
prek run (staged files only)
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run |
48.8 ± 1.2 | 47.2 | 51.7 | 1.00 ± 0.03 |
prek-head run |
48.6 ± 1.0 | 46.8 | 50.0 | 1.00 |
prek run --files '*.json' (specific file type)
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run --files '*.json' |
8.3 ± 0.1 | 8.1 | 8.5 | 1.01 ± 0.02 |
prek-head run --files '*.json' |
8.2 ± 0.2 | 7.9 | 8.6 | 1.00 |
Workspace Discovery & Initialization
Benchmarking hook discovery and initialization overhead:
prek run --dry-run --all-files (measures init overhead)
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run --dry-run --all-files |
10.7 ± 0.2 | 10.4 | 11.1 | 1.01 ± 0.03 |
prek-head run --dry-run --all-files |
10.6 ± 0.2 | 10.2 | 11.0 | 1.00 |
Meta Hooks Performance
Benchmarking meta hooks separately:
prek run check-hooks-apply --all-files
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run check-hooks-apply --all-files |
12.6 ± 0.5 | 11.4 | 13.1 | 1.10 ± 0.05 |
prek-head run check-hooks-apply --all-files |
11.4 ± 0.2 | 11.2 | 11.7 | 1.00 |
prek run check-useless-excludes --all-files
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run check-useless-excludes --all-files |
11.4 ± 0.2 | 11.1 | 11.7 | 1.01 ± 0.02 |
prek-head run check-useless-excludes --all-files |
11.3 ± 0.2 | 11.1 | 11.9 | 1.00 |
prek run identity --all-files
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run identity --all-files |
10.4 ± 0.1 | 10.3 | 10.5 | 1.00 |
prek-head run identity --all-files |
10.8 ± 0.4 | 10.3 | 11.5 | 1.04 ± 0.04 |
|
Thanks! |
Remove unnecessary clones when the receiver can be moved instead, since it is no longer used afterwards.
CC @nunoplopes