ejv2 / podbit

Podboat - Improved
GNU General Public License v3.0
26 stars 1 forks source link

Completely rework event passing system #5

Closed ejv2 closed 2 years ago

ejv2 commented 2 years ago

This is currently the top output on my system:

Tasks: 223 total,   1 running, 221 sleeping,   0 stopped,   1 zombie
%Cpu(s):  4.6 us,  1.5 sy,  0.0 ni, 92.3 id,  0.0 wa,  1.5 hi,  0.0 si,  0.0 st
MiB Mem :   3806.9 total,   1036.4 free,   1560.0 used,   1210.4 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used.   1729.1 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
22075 ethan     20   0 1452916  26244   4660 S  12.5   0.7   4:52.15 podbit
15803 ethan     20   0    8452   3640   2892 R   6.2   0.1   0:00.01 top
    1 root      20   0    1092      4      0 S   0.0   0.0   0:03.70 runit
    2 root      20   0       0      0      0 S   0.0   0.0   0:00.32 kthreadd
    3 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 rcu_gp
    4 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 rcu_par_gp
    5 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 netns
    9 root       0 -20       0      0      0 I   0.0   0.0   0:04.29 kworker/0:1H-kblockd

This is unacceptable for a CLI podcast application, especially for an event driven one, and is twice as high as the next realtime CLI (top). It is almost 100 times higher than ncmpcpp, which is the design basis for podbit. I want to completely rework the event passing system such that podbit is idle for 90% of its runtime at least. This should be spent waiting on IO and channel events, ideally. This particular state was entered while the media was paused, which causes a complete screen redraw each second.

Plan

Add package events (or package ev which is shorter) which coordinates every other system in podbit together through an abstracted channel of events passed between systems. Each system has a single channel over which it can recieve events which inform it of what to do and when. This allows coordination between the sound subsystem and the UI subsystem and everything else inbertween.

The current system relies on a web of tangled mutexes, which can cause weird deadlocks in unexpected places (for instance, if your mpv instance dies). This system should be more robust and event-driven, as initially intended.

Roadmap

I will fill a TODO list here as needed