kondo icon indicating copy to clipboard operation
kondo copied to clipboard

Look into parallelisation

Open tbillington opened this issue 5 years ago • 7 comments

Look into parallelisation options such as rayon, crossbeam, or even tokio for parallelisation. Much of what kondo does is able to be done in parallel.

tbillington avatar Jan 28 '20 02:01 tbillington

I think the best approach here would likely be to try using tokio or async-std to get asynchronous IO. I might try spinning up a fork with this later this week when I have time.

Noah-Kennedy avatar May 16 '20 20:05 Noah-Kennedy

Neat :) I'd recommend looking for inspiration in ripgrep (https://github.com/BurntSushi/ripgrep/tree/master/crates/ignore). It does parallel file searching without requiring an entire async runtime and gets better performance for it. Not sure how complex it is though.

tbillington avatar May 17 '20 03:05 tbillington

Another reason that multithreading would be good: on wayland the compositor expects to be able to ping the UI often. If the UI thread blocks (as is the case with the clean method), then the compositor sometimes kills the app. The solution is to do all work in a separate thread and communicate using messages.

richard-uk1 avatar Dec 18 '20 12:12 richard-uk1

Ah that's interesting, I didn't know that!

tbillington avatar Dec 20 '20 06:12 tbillington

@derekdreery kondo switched to using multiple threads for the CLI in https://github.com/tbillington/kondo/commit/1dcc3684c7e2b249d736d60a7e174fa7e8834359.

It now uses 3 threads, one for running ahead of the user input that "discovers" the projects, one for presenting them to the user and receiving the users action, and one for cleaning the projects the user has chosen.

They communicate via channels and don't block each other. The only limit I've set is the discover thread will only find up to 5 projects ahead of the UI thread, mostly to avoid unnecessary work if the user exits early.

tbillington avatar Jul 06 '23 04:07 tbillington

I'm open to more parallelism, but since the CLI is now not blocked by discovery or cleaning it feels very snappy to use.

It's also very fast as is for my use case now, so I have less motivation for a solution based on multithreaded async work, but I'm still not opposed to the idea.

tbillington avatar Jul 06 '23 05:07 tbillington

FWIW I disagree with my original statement from three years ago, as I know a lot more about the subject now.

If you want to do some sort of async thing, io_uring on linux would allow for more speed on that platform, but other than that you won't see gains from just slapping async onto things.

Noah-Kennedy avatar Jul 07 '23 19:07 Noah-Kennedy