Implement backpressure mechanism for iced_winit::Proxy
#2389
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 squidowl/halloy#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.