Skip to content

Switch from pre-commit to prek#31081

Open
QuLogic wants to merge 1 commit intomatplotlib:mainfrom
QuLogic:prek
Open

Switch from pre-commit to prek#31081
QuLogic wants to merge 1 commit intomatplotlib:mainfrom
QuLogic:prek

Conversation

@QuLogic
Copy link
Member

@QuLogic QuLogic commented Feb 5, 2026

PR summary

Following the benchmarks from Hugo van Kemenade, we get about 3× faster with prek:

pre-commit prek Ratio
run --all-files 4m52.503s 1m26.718s 3.373
install-hooks 3m31.002s 1m6.608s 3.168
hyperfine 176.214 58.500 3.01

with hyperfine results of:

Benchmark 1: prek install-hooks
  Time (mean ± σ):     58.500 s ± 15.029 s    [User: 8.485 s, System: 3.138 s]
  Range (min … max):   30.766 s … 76.617 s    10 runs

Benchmark 2: pre-commit install-hooks
  Time (mean ± σ):     176.214 s ± 11.544 s    [User: 31.003 s, System: 5.127 s]
  Range (min … max):   161.969 s … 198.271 s    10 runs

Summary
  prek install-hooks ran
    3.01 ± 0.80 times faster than pre-commit install-hooks

These benchmarks were run on my desktop, which is several generations behind, but was more idle than my laptop. I would run on my laptop (which is still about 5 years old), but I don't really want to wait for hyperfine to do another long run like that.

Since we aren't using pre-commit's CI anyway, it's easy to switch GitHub Actions directly.

PR checklist

Following the [benchmarks from Hugo van
Kemenade](https://hugovk.dev/blog/2025/ready-prek-go/), we get about 3×
faster with prek:
|                 | pre-commit | prek      | Ratio |
| --------------- | ---------- | --------- | ----- |
| run --all-files | 4m52.503s  | 1m26.718s | 3.373 |
| install-hooks   | 3m31.002s  | 1m6.608s  | 3.168 |
| hyperfine       | 176.214    | 58.500    | 3.01  |

with hyperfine results of:
```
Benchmark 1: prek install-hooks
  Time (mean ± σ):     58.500 s ± 15.029 s    [User: 8.485 s, System: 3.138 s]
  Range (min … max):   30.766 s … 76.617 s    10 runs

Benchmark 2: pre-commit install-hooks
  Time (mean ± σ):     176.214 s ± 11.544 s    [User: 31.003 s, System: 5.127 s]
  Range (min … max):   161.969 s … 198.271 s    10 runs

Summary
  prek install-hooks ran
    3.01 ± 0.80 times faster than pre-commit install-hooks
```
@QuLogic QuLogic added the status: needs comment/discussion needs consensus on next step label Feb 5, 2026
@github-actions github-actions bot added the Documentation: devdocs files in doc/devel label Feb 5, 2026
@tacaswell
Copy link
Member

Sounds like upstream of prek is also reasonable to work with which is a major plus.

Copy link
Member

@story645 story645 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating the dev docs!

@rcomer
Copy link
Member

rcomer commented Feb 5, 2026

Where does the speedup for run come from? Is it just that run is also installing or is something else going on?

@QuLogic
Copy link
Member Author

QuLogic commented Feb 5, 2026

This is without the cache, so it is also installing all venvs required for running the linters. For day-to-day, it's probably not so much faster, except when we start changing configs or something that requires rebuilding them. As Hugo mentioned, I think, this doesn't do anything for speeding up the linters themselves. That is, mypy is probably going to be the slowest thing if it has to go through all files. While prek does have a fast path for some of the regular hooks, I don't think we have enough code for those to dominate times at all.

If I edit one file, git add it, and run without --all-files, it's about 1.21× faster (but still pretty quick):

$ hyperfine 'prek run' 'pre-commit run'
Benchmark 1: prek run
  Time (mean ± σ):     881.3 ms ± 210.7 ms    [User: 412.3 ms, System: 186.2 ms]
  Range (min … max):   584.5 ms … 1266.8 ms    10 runs
 
Benchmark 2: pre-commit run
  Time (mean ± σ):      1.063 s ±  0.114 s    [User: 0.671 s, System: 0.244 s]
  Range (min … max):    0.908 s …  1.292 s    10 runs
 
Summary
  prek run ran
    1.21 ± 0.32 times faster than pre-commit run

@rcomer
Copy link
Member

rcomer commented Feb 5, 2026

Even just the install speedup is nice to have. Yesterday I used my clone on my work machine for the first time in a while, and was kind of annoyed about having to wait for those hooks to install!

@bjlittle
Copy link

bjlittle commented Feb 5, 2026

The improved disk usage offered by prek over pre-commit is a BIG and most welcome win AFAIK 💪

The number of times I've had to purge a scary amount of GBs from my pre-commit cache ... lost count 😬

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation: devdocs files in doc/devel status: needs comment/discussion needs consensus on next step

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants