aaronjanse / 3mux

Terminal multiplexer inspired by i3
MIT License
1.82k stars 46 forks source link

significantly reduce idle CPU usage #103

Closed aaronjanse closed 3 years ago

aaronjanse commented 3 years ago

With #97 now merged, 3mux no longer writes to stdout when idling (none of the panes are changing). This PR tells the renderer to "sleep" if it hasn't received any HandleCh calls for the past second. "Sleeping" means waiting on a channel then letting HandleCh send something to that channel to restart the renderer's loop.

This reduces idle CPU usage from ~1.5% to ~0% on my laptop.

I'm unsure how the pause/resume channels should be handled while asleep? (thus, this PR is marked as a draft)

PotatoParser commented 3 years ago

So here are my thoughts on sleeping channels:

  1. Don't go on idle when there is a running task (we don't know whether or not it might send an stdout or ask for an stdin all of a sudden)
  2. When sleeping, you no longer need to loop to test for idle. Immediately wake on a user input (any keystroke in that pane).
  3. Not sure if ListenToQueue is applied on all the panes, but it should be a good idea to be able to idle individual panes
  4. Panes hop off idle when you switch to them (this allows you to immediately start collecting data while not worrying about gains in latency)
aaronjanse commented 3 years ago

Panes handle all that stuff quite well (TM), the same way as tmux [1]. This PR is about the global renderer.... and your comment made me realize we should just re-use logic from pane drawing for the global renderer!

I'll make a new PR to do this :-)

[1] https://github.com/tmux/tmux/issues/849#issuecomment-291828893