zlacker

[parent] [thread] 32 comments
1. judofy+(OP)[view] [source] 2025-02-17 17:20:48
> lefthook is written in go, hk is written in rust. This will make hk faster but the advanced parallelism logic in hk should make hk much faster. Because git hook managers are often limited not by their own logic but the speed of the commands they run, this should make hk significantly faster in real-world usage.

What a strange sentence. First Hk will be faster than Lefthook because it will be written in Rust[1], but then later on it says that it doesn't actually matter? But either way it will be faster because it has "advanced parallelism"?

Looking at the comparison to Lefthook it's not clear to me why this isn't a PR to Lefthook. It's already a well-established solution which is present in many package managers. Surely the distinction between "checks" and "fixes" would be possible to introduce there as well?

Do we yet another tool instead of working together on improving the existing ones?

[1]: Which also is not a given. Programs which allocate a lot can be faster in Go since the garbage collector only works on the live set of objects whereas Rust have to explicitly deallocate all memory. CLI tooling is actually kinda a sweet-spot of GCs: You don't want to spend time reclaiming memory until you reach a certain threshold of used memory. In scenarios where you use less than the threshold you end up spending zero cycles on deallocation. (And completely leaking all memory is bound to cause problem on bigger commands or smaller machines.)

replies(5): >>searea+k >>doug_d+M3 >>Arech+w7 >>WhyNot+fa >>jdxcod+Ox
2. searea+k[view] [source] 2025-02-17 17:22:06
>>judofy+(OP)
It makes sense. If you have 4 hooks, and you run them serially, it will be slower than if you ran them in parallel.
replies(3): >>vlovic+66 >>rounce+d6 >>great_+n6
3. doug_d+M3[view] [source] 2025-02-17 17:43:17
>>judofy+(OP)
Why mention Rust at all? How is that possibly relevant to the problem? There seems to be a lot of projects that are rewrites of existing project in Rust where the fact that they are in Rust seems to be their distinguishing feature. Languages are less important than the solutions that a piece of software provides.
replies(4): >>codetr+q5 >>unshav+j7 >>jayd16+1b >>dsff3f+Yv
◧◩
4. codetr+q5[view] [source] [discussion] 2025-02-17 17:53:08
>>doug_d+M3
> Why mention Rust at all? How is that possibly relevant to the problem?

There are a lot of command line tools that are written in JS and other scripting languages.

Having the tools that are involved in interactive use be written in a compiled languages gives hope that they might be fast enough to not be annoying.

Me personally I do not install nodejs on my machines. So knowing that this tool is not written in JS is relevant for me.

replies(1): >>acheon+I8
◧◩
5. vlovic+66[view] [source] [discussion] 2025-02-17 17:57:47
>>searea+k
I say this as a huge fan of Rust, Rust adds almost nothing to this kind of parallelism.
replies(1): >>searea+fv
◧◩
6. rounce+d6[view] [source] [discussion] 2025-02-17 17:58:37
>>searea+k
That assumes the hooks themselves can be run in parallel. Without a way to describe dependencies between them there's big scope for race conditions.
replies(2): >>goku12+u9 >>thayne+vw
◧◩
7. great_+n6[view] [source] [discussion] 2025-02-17 17:59:37
>>searea+k
Sure, but Go can do things in parallel too. How is Rust's faster than Go's, especially if they're limited by the speed of the commands they run?
replies(2): >>unshav+G7 >>Izkata+ZH
◧◩
8. unshav+j7[view] [source] [discussion] 2025-02-17 18:05:17
>>doug_d+M3
I prefer knowing what language things are written in. Not only is it interesting, but i like knowing what sort of installation i have to look forward to, if i'm interested in contributing, etc.
9. Arech+w7[view] [source] 2025-02-17 18:06:51
>>judofy+(OP)
Overall, the whole logic "A is written in X, but B is written in Y, hence it is faster" is so deeply flawed, that one has to consider a possibility that the author doesn't understand the mere basics of computer program engineering. There are so much nuances that I don't even want to start untangling it.
replies(2): >>WhyNot+ya >>sgarla+Cg
◧◩◪
10. unshav+G7[view] [source] [discussion] 2025-02-17 18:08:15
>>great_+n6
Imo this problem would be fine in either Go or Rust. I've done both. For extreme cases you can, i imagine, make Rust parallelism faster than Gos, but by default if you just design them similarly -- eg: throwing Tokio at the problem and not hyper optimizing Rust -- i imagine they'd perform quite similarly.

As much as i'm a proponent of Rust, Go is very capable and is generally a great language. Its warts (as i see them) are not going to be apparent in the parallelism needed for a Git hook manager lol.

◧◩◪
11. acheon+I8[view] [source] [discussion] 2025-02-17 18:15:24
>>codetr+q5
> There are a lot of command line tools that are written in JS and other scripting languages.

???

Also, this tool replaces another which was written in Go, which I would put in a similar performance category as Rust. It shouldn't make a difference in this scenario

◧◩◪
12. goku12+u9[view] [source] [discussion] 2025-02-17 18:22:16
>>rounce+d6
Hooks are generally not meant to modify the source code. They should ideally just analyze the code and either succeed (exit code 0) or fail. Race conditions won't happen in such situations.

In practice though, hooks sometimes run tools that are were not designed like that and instead modify the file (eg: formatters). However, this is usually done on staged files (in case of the pre-commit hook) and the modification is applied to the working copy. This can cause race condition in that one tool may overwrite the changes made by another tool. But since the source is not modified, it won't end up in a deadlock. It will also fail as desired. So the race is not serious. It will resolve itself after a few runs, unless something is done to prevent it in the first place.

13. WhyNot+fa[view] [source] 2025-02-17 18:27:09
>>judofy+(OP)
It says should be much faster, which makes me think they’re talking about performance but haven’t actually compared it.

I find hk's choice of programming language for hooks pretty exotic TBH.

This all made me look at lefthook, and it’s pretty darn interesting. I’d been missing out!

replies(1): >>jdxcod+2n
◧◩
14. WhyNot+ya[view] [source] [discussion] 2025-02-17 18:29:52
>>Arech+w7
Agreed. And for tools like this (which are light wrappers around much heavier tools), the difference in performance is insignificant. It’s all the other factors that start to matter.
◧◩
15. jayd16+1b[view] [source] [discussion] 2025-02-17 18:32:50
>>doug_d+M3
If they didn't mention the language, it would be an immediate question. The main focus is parallelism.

Could the Go solution add parallelism, sure. Did they? Not yet. Does that mean no other improvement in any other language can ever be written? No.

"Rust is faster" as an off the cuff comment that should have been left out seeing it has triggered some folks to hyper focus on that point.

replies(1): >>judofy+sd
◧◩◪
16. judofy+sd[view] [source] [discussion] 2025-02-17 18:48:34
>>jayd16+1b
> Could the Go solution add parallelism, sure. Did they? Not yet.

They did: Lefthook lets you define a "group" where you can specify that every command should be done in parallel: https://lefthook.dev/configuration/group.html. In addition, it's possible to configure the whole hook to run in parallel through another property: https://lefthook.dev/configuration/parallel.html.

I'm assuming that Hk's innovation here is that it's a bit smarter with what it runs in parallel. Maybe it uses the globs to automatically run commands in parallel which targets different files?

> "Rust is faster" as an off the cuff comment that should have been left out seeing it has triggered some folks to hyper focus on that point.

It's not a a hyper focus: This was the first reason (out of only three) that Hk itself presented as a reason to use it over Lefthook. So yes, I agree: It should have been left out if the intention wasn't for people to focus on it. Put it somewhere in a footnote if it's not so relevant.

◧◩
17. sgarla+Cg[view] [source] [discussion] 2025-02-17 19:07:18
>>Arech+w7
mise (née rtx), by the same author, could confidently claim this because the tool it replaced – asdf – is written in bash. Bash is perfectly capable for a great many things, but unless you’re getting fairly deep into the weeds of what it can do (e.g. eschewing external calls to sed et al. whenever possible in favor of parameter substitution), you’ll tank performance from sub-shell spawn times. mise was objectively and obviously faster out of the box, though nearly any language that included basic text processing functionality would’ve been acceptably fast.

In general though, I agree that the blanket statement of “X is good because it’s language Y” is absurd, though I stubbornly cling to the opposite case for NodeJS, because I despise the idea of a frontend language running anything but a browser window. I have no objective defense.

replies(1): >>dlisbo+Qk
◧◩◪
18. dlisbo+Qk[view] [source] [discussion] 2025-02-17 19:33:11
>>sgarla+Cg
`asdf` has now been rewritten in Go for anyone interested, so choosing mise over it due to performance is less of a concern now.
replies(1): >>sgarla+o4c
◧◩
19. jdxcod+2n[view] [source] [discussion] 2025-02-17 19:47:22
>>WhyNot+fa
I haven't even built it, let alone benchmark it. I don't think people are realizing this thing is like a 3 day old project (in terms of actual work). The about page is a bunch of scratch I wrote today (and didn't even finish that doc before I moved onto something else).
◧◩◪
20. searea+fv[view] [source] [discussion] 2025-02-17 20:49:28
>>vlovic+66
It doesn't claim that.

It claims:

1) Rust is fast, so that helps some.

2) They run hooks in parallel, and that helps a lot.

replies(1): >>vlovic+J51
◧◩
21. dsff3f+Yv[view] [source] [discussion] 2025-02-17 20:54:37
>>doug_d+M3
> Why mention Rust at all?

I like knowing what language a tool is written in. If it's written in Python or JavaScript and it isn't something that's absolutely essential I can just immediately move on. It also lets me know if it's something I'd be willing to contribute to. It's odd that the authors mentioning the language is so triggering for you.

◧◩◪
22. thayne+vw[view] [source] [discussion] 2025-02-17 20:57:56
>>rounce+d6
Which is why it is best if you plan for parallelism from the beginning, so that your configuration has a straightforward way to indicate dependencies and making sure certain hooks aren't run in parallel with conflicting hooks
replies(1): >>rounce+TH
23. jdxcod+Ox[view] [source] 2025-02-17 21:10:20
>>judofy+(OP)
This project is brand new. I've only spent 3 days on it and this doc I half finished today. That said, I just did some benchmarks and it certainly is much faster than its peers. 4.6x faster than lefthook and 6.1x faster than pre-commit (in the best case).

I'll put these benchmarks on that page in different scenarios.

Update: https://github.com/jdx/hk/blob/main/docs/public/benchmark.pn...

As I said in the doc I think real-world performance in a large codebase will show that hk is even faster still—though that will depend on the project in question. It's really just a matter of providing the right levers in the right places and having good defaults.

Despite what everyone here says: yeah, just doing CLIs in Rust will be faster than Go and for CLIs like this milliseconds matter.

replies(2): >>judofy+OK >>onnimo+VO
◧◩◪◨
24. rounce+TH[view] [source] [discussion] 2025-02-17 22:33:59
>>thayne+vw
The subject program doesn't seem to provide a way in which to specify the dependencies between hooks, hence they will just race each other assuming they are all fired off in parallel.
replies(1): >>jdxcod+pT1
◧◩◪
25. Izkata+ZH[view] [source] [discussion] 2025-02-17 22:34:36
>>great_+n6
It mentions "lefthook" by name. I'm guessing that specific go-based hook manager doesn't do this parallelism. So it's saying "rust instead of go might give a small performance boost, but that's not where most of the performance boost comes from".
◧◩
26. judofy+OK[view] [source] [discussion] 2025-02-17 23:06:23
>>jdxcod+Ox
I'm sorry, but it's very hard to take this project seriously: You originally claimed that it was 1.5x faster than Lefthook, but then you removed the parallel support from the Lefthook (https://github.com/jdx/hk/commit/ad473331db2866f6574555ac4b0...) and changed your claim to "4.6x faster". These numbers are also just for some a specific workload (Prettier, ActionLint, pkl eval, ripgrep, cargo fmt) on this specific repo. For now the "4.6x number" is heavily based on the fact you have five jobs and Hk runs commands in parallel by default while you let Lefthook run them sequentially. I bet you can turn that number into 10x if you just add a few more jobs!

> Despite what everyone here says: yeah, just doing CLIs in Rust will be faster than Go and for CLIs like this milliseconds matter.

You've shown nothing to suggest that this is true. On my computer "lefthook --help" is exactly as fast as "hk --help". There's also many other differences between these tools. YAML vs Pkl is one difference. Another one is that Lefthook shells out to "git" to determine the list of staged files, while Hk uses libgit2. Which of these are faster? I'm not sure! It might even depend on repository size and/or other details. And as we all agree: In practice the parallelism strategy will matter the most.

> As I said in the doc I think real-world performance in a large codebase will show that hk is even faster still

I'm absolutely sure that you will be able to tweak hk to become the "fastest" pre-commit runner in your designated category. I'm also pretty sure that similar optimizations will apply quite easily to Lefthook. They're after all doing pretty much the same thing.

replies(1): >>jdxcod+QL
◧◩◪
27. jdxcod+QL[view] [source] [discussion] 2025-02-17 23:16:35
>>judofy+OK
of course I selected the best benchmark. Once I ran a benchmark that had higher numbers I edited my response—I was up front about that. So far 0 benchmarks show that lefthook is faster and I doubt there could be one knowing how both of them work. I'm not just creating scenarios where I know hk will outperform but I'll certainly highlight the best one.

> then you removed the parallel support

that was not intentional. I fixed that, but it didn't change the results that much:

https://github.com/jdx/hk/commit/dfe1fc1724b8f6c43b184dc98ac...

In any case, I don't know why anyone would take such a new project "seriously". I certainly don't.

◧◩
28. onnimo+VO[view] [source] [discussion] 2025-02-17 23:48:00
>>jdxcod+Ox
Thanks for creating and sharing this :) Commenters here can be pretty awful so I wanted to say that I really enjoy using the tools you have created.
◧◩◪◨
29. vlovic+J51[view] [source] [discussion] 2025-02-18 02:19:46
>>searea+fv
I was replying to OP not the article. The article really muddles through and hand waves away the Rust vs Go - I’m seriously skeptical the overhead of the language would show up at all with the work being done here.
replies(1): >>searea+Ei1
◧◩◪◨⬒
30. searea+Ei1[view] [source] [discussion] 2025-02-18 05:00:17
>>vlovic+J51
You are moving the goalposts? You first claimed that Rust doesn't help with parallelism. I pointed out they never claimed it did. Now you are talking about something else?
replies(1): >>vlovic+Yx1
◧◩◪◨⬒⬓
31. vlovic+Yx1[view] [source] [discussion] 2025-02-18 08:03:23
>>searea+Ei1
> lefthook is written in go, hk is written in rust. This will make hk faster

Direct claim from the article.

◧◩◪◨⬒
32. jdxcod+pT1[view] [source] [discussion] 2025-02-18 11:50:45
>>rounce+TH
in fact I do believe I have a solution to this problem. I should have this fully implemented soon but right now it is not.

First, I intend to be able to define simple "dependencies", but IMO that's not the interesting part.

I am going to use rw mutexes on every file with staged changes. If 2 steps are running against disjoint files there is no problem. If 2 steps are running against "check" (not "fix" which edit files by convention), they can also run at the same time. The only scenario where blocking is necessary is when you have 2 "fix" or 1 "check" and 1 "fix" on an intersection of their files.

For that scenario there is going to be a setting that you can enable to run a steps "check" command first (only if this scenario is about to happen, if no files will be in contention it will simply run "fix"), and if "check" fails, then it will switch to "fix".

This is my current idea and in my head I think it would work. There are caveats, notably running "check" and then "fix" might be slower than just waiting and running "fix" once which is why it needs to be optional behavior. You also may not care about things stomping on each other (maybe the linters themselves have their own locking logic).

◧◩◪◨
33. sgarla+o4c[view] [source] [discussion] 2025-02-21 14:10:51
>>dlisbo+Qk
Oh, good to know! Kinda sad that they gave up on bash; I wonder how they’ll differentiate themselves now.

I had submitted a PoC patch for the bash version that greatly sped it up, but there were a couple of tests I was struggling to get to pass, and I ran out of free time.

[go to top]