Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
calloop PR: reuse the poll events buffer across dispatches
Repo: https://github.com/Smithay/calloop (fork it, branch
reuse-poll-events)Base:
masterat1e9def9a3f8ce1417e559cc57a549a9516ea5aacPatch:
calloop.patch(next to this file;git apply calloop.patchon that base)Checked on that base:
cargo fmt --checkclean,cargo test: 48 + 3 + 1 passed. The new testfails on the unpatched crate (0.14.5: 1000 allocations in 1000 dispatches).
Our vendored copy (
vendor/calloop, 0.14.5) carries the same change.Title
Reuse the poll events buffer across dispatches
Body
Poll::pollcollects each wake's ready events into a newVec<PollEvent>, so everyEventLoop::dispatchthat finds a ready source allocates (48 bytes for one event on x86-64) andfrees it again. A GUI client wakes for its display connection about once a frame, which puts one
allocation into every frame. winit's Wayland backend dispatches through calloop, so every winit
app on Wayland pays this cost. We found it while enforcing a zero-allocation steady-state frame in
a game. heaptrack showed it as the only remaining per-frame allocation besides one in
wayland-backend (Smithay/wayland-rs#TODO).
This change:
EventLoopkeeps apoll_events: Vec<PollEvent>next to its existingsynthetic_eventsbuffer.Poll::poll(crate-private) takes&mut Vec<PollEvent>, clears it and refills it, instead ofreturning a new
Vec.dispatch_eventsiterates and drains that buffer, so its capacity survives to the next dispatch.The level-triggered re-registration, the timer events and the error paths are unchanged. No
public API changes.
A new integration test,
tests/dispatch_allocations.rs, counts allocations through a thread-localcounting global allocator. It warms up once, then dispatches a ready
Genericsource 1000 timesand asserts zero allocations. Without the change it reports 1000.
🤖 Generated with Claude Code
https://claude.ai/code/session_01NwaQZQwdPnpxWEikdEfVvo