The EventLoopProxy in winit is implemented using an unbounded mpsc channel. In practice, this means that we have to be careful when publishing to this channel, as it will simply keep allocating additional memory when needed. And guess what? We are not careful at all!
Currently, if a Subscription decides to start producing messages very quickly—faster than update can process them—the messages will start piling up in the EventLoopProxy and memory usage will increase indefinitely. Furthermore, this memory will stay allocated as channel capacity once the application catches up and the messages are processed. I suspect this could be the root cause of some high memory usage reports (like https://github.com/squidowl/halloy/issues/309).
The solution implemented in this PR consists in connecting the output of an async, bounded mpsc channel to the EventLoopProxy input while freeing new message slots when published messages are processed by update—effectively achieving backpressure for all of our async abstractions.
The
EventLoopProxy
inwinit
is implemented using an unboundedmpsc
channel. In practice, this means that we have to be careful when publishing to this channel, as it will simply keep allocating additional memory when needed. And guess what? We are not careful at all!Currently, if a
Subscription
decides to start producing messages very quickly—faster thanupdate
can process them—the messages will start piling up in theEventLoopProxy
and memory usage will increase indefinitely. Furthermore, this memory will stay allocated as channel capacity once the application catches up and the messages are processed. I suspect this could be the root cause of some high memory usage reports (like https://github.com/squidowl/halloy/issues/309).The solution implemented in this PR consists in connecting the output of an async, bounded
mpsc
channel to theEventLoopProxy
input while freeing new message slots when published messages are processed byupdate
—effectively achieving backpressure for all of our async abstractions.