Today, on matters concerning my existence...
An 8 month delayed update!
Introducing: easy-window-switcher-rs! (it's like easy-window-switcher but in RUST)
Yes, after writing the last post during my Christmas break, I did end up rewriting my easy-window-switcher from Python to Rust. I'm just only now bothering to write the follow up post to announce that it was rewritten: easy-window-switcher-rs! (I know, very creative name)
How did it turn out?
Great! Not only is it no longer written in the worst-language-on-Earth (Python), it's written in the greatest-language-on-Earth (Rust)!
In all seriousness, as much as I never really complained that the Python version was noticeably slow... I must say, the Rust version is like ever so slightly noticeably faster. It just feels instantaneous to invoke and switch between windows, so that's a nice usability win.
Oh yeah, looking at my old notes, I even did some timing tests between the two versions:
$ (start=$(date +%s%3N); easywindowswitcher direction left; end=$(date +%s%3N); echo "Elapsed time: $((end - start)) ms")
Elapsed time: 162 ms
$ (start=$(date +%s%3N); easy-window-switcher-rs direction left; end=$(date +%s%3N); echo "Elapsed time: $((end - start)) ms")
Elapsed time: 30 ms
$ (start=$(date +%s%3N); easywindowswitcher monitor 0; end=$(date +%s%3N); echo "Elapsed time: $((end - start)) ms")
Elapsed time: 165 ms
$ (start=$(date +%s%3N); easy-window-switcher-rs monitor 0; end=$(date +%s%3N); echo "Elapsed time: $((end - start)) ms")
Elapsed time: 22 ms
The Rust rewrite (in its most naive implementation) is about 5 times faster, and I suspect most of the actual execution time is just the time we spend calling out to the other CLI tools, so that's neat.
On top of that, one of my original goals was to improve the configurability of the tool since the monitor layout was hard-coded into the source code before. Well now, not only is it "more configurable", it's automatic. I went above and beyond centralizing the config to just outright making it detect and work with the computer's actual monitor configuration! (thanks to adding xrandr
as another dependency)
That being said, I didn't exactly rigorously test it with different monitor setups, but it works for mine and that's good enough for me!
Final Thoughts
Was this rewrite worth it just as a time waster? Yes!
Is the new version better in every way? Absolutely!
Mission? Success!
Rust really is quite nice for writing CLI tools. I should do this again some day.
But until then...
You should really go learn some Elixir :)