kamiyaa / joshuto

ranger-like terminal file manager written in Rust
https://crates.io/crates/joshuto
GNU Lesser General Public License v3.0
3.37k stars 148 forks source link

Migration to Tokio #419

Open kamiyaa opened 11 months ago

kamiyaa commented 11 months ago

Thinking of taking advantage of async/await and green threads to potentially make joshuto more lightweight. Would love to hear some feedback on this. Not entirely sure if it will help with performance, or just increase build times.

Beethoven-n commented 11 months ago

i think it might be worth fixing the arm build issues first, so chromebooks and macs can use joshuto. i'd do it after that point, if it were me

kamiyaa commented 11 months ago

i think it might be worth fixing the arm build issues first, so chromebooks and macs can use joshuto. i'd do it after that point, if it were me

What issues are you having on arm? I'm able to compile and run joshuto on m2 macbook

Lzzzzzt commented 10 months ago

are there some ways to run benchmark between tokio version and current version

kamiyaa commented 10 months ago

are there some ways to run benchmark between tokio version and current version

Good question

Beethoven-n commented 10 months ago

i think it might be worth fixing the arm build issues first, so chromebooks and macs can use joshuto. i'd do it after that point, if it were me

What issues are you having on arm? I'm able to compile and run joshuto on m2 macbook

joshuto still doesn't compile on termux with a mismatched types error at src/ui/widgets/tui_file_preview.rs:44:45

fritzrehde commented 9 months ago

My take on using Tokio (I use Tokio/async Rust in my own TUI project called watchbind): You have to either go all in on Tokio/async Rust or not use it at all. This is because you are not really allowed to call synchronous code inside async functions, and most of your functions will become async, otherwise these synchronous calls will block the entire application and destroy the purpose of an async runtime (there are ways to mitigate this, but all I know of is basically performing sync function calls on a separate thread. Tokio has good docs on this). For me, a huge advantage of async Rust is: I can wait for multiple async functions to complete at once with select!, and then do whatever I want when the first one completes. I know this might not be relevant for your application, but it helped me get rid of some ugly/inefficient uses of active polling. Anyways, Tokio has nice support for async file IO. It also has equivalents for pretty much everything you would need/already use (e.g. mpsc channels etc.). I'm personally very happy that I made the switch to Tokio and async Rust, I learned a lot about it, but it's also not super trivial. If you're not familiar with async Rust/Tokio yet, I can highly recommend Crust of Rust: async/await YouTube video by Jon Gjengset. Switching to Tokio would probably be quite a big refactor, so you'd have to evaluate whether it's worth it. I know of (but haven't used) yazi, which is another TUI file manager in Rust that indeed uses async Rust. Maybe you can look at their code, or ask more specific questions there.

fritzrehde commented 9 months ago

I just found this issue in yazi describing some of their usage of Tokio, might be useful to check out.