Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement backpressure mechanism for iced_winit::Proxy #2389

Merged
merged 2 commits into from
Apr 17, 2024

Conversation

hecrj
Copy link
Member

@hecrj hecrj commented Apr 16, 2024

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 squidowl/halloy#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.

@hecrj hecrj added bug Something isn't working performance subscription fix labels Apr 16, 2024
@hecrj hecrj added this to the 0.13 milestone Apr 16, 2024
@hecrj hecrj merged commit d8ce7bc into master Apr 17, 2024
24 checks passed
@hecrj hecrj deleted the fix/async-memory-usage branch April 17, 2024 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant