Replace idle sleep with a wakeable SDL wait#286
Merged
forketyfork merged 2 commits intomainfrom Apr 13, 2026
Merged
Conversation
Issue: Replace Architect's fixed idle sleep with a wakeable wait so typing and other visible events no longer inherit an avoidable delay after the app has gone idle. Solution: Move frame pacing into explicit wait-decision helpers and let idle frames block in SDL until either an input event arrives or the next idle deadline expires. Keep active non-vsync pacing unchanged, and have the notification thread post a custom SDL wake event after it queues external status updates so the runtime loop wakes immediately.
There was a problem hiding this comment.
Pull request overview
This PR updates Architect’s main frame loop to eliminate the fixed 50ms “idle sleep” and instead block in SDL with a wakeable wait, so user input and external notifications can wake the app immediately while still preserving existing active-frame pacing behavior.
Changes:
- Adds a frame-wait strategy (
FrameWaitDecision) and usesSDL_WaitEventTimeout(...)while idle to reduce perceived typing latency. - Posts a custom SDL user event from the notification thread after enqueuing notifications to wake the idle loop promptly.
- Updates docs/README to describe the new wakeable idle model and adds tests around the new wait-decision helpers.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/session/notify.zig | Adds optional runtime wake callback and triggers it after successful notification enqueue. |
| src/platform/sdl.zig | Registers a custom SDL event type and provides helpers to wait/push/identify wake events. |
| src/c.zig | Re-exports additional SDL event/wait/push APIs needed for wakeable waiting. |
| src/app/runtime.zig | Replaces idle sleeping with an SDL wait strategy; integrates wake events into the event-drain loop; adds unit tests for wait computations. |
| README.md | Notes wakeable idle input handling as a feature. |
| docs/ARCHITECTURE.md | Documents the new wakeable wait model in the frame loop. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Issue: Follow up on PR review comments for the wakeable idle wait change covering wake-event error handling, idle timeout rounding, and notify-path test coverage. Solution: Log SDL wake-event push failures instead of ignoring them, round idle waits up so idle pacing does not wake early, and extract the queue-and-wake path in the notify module into a shared helper so tests exercise the real integration behavior, including the no-wake-on-queue-failure case.
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.
Fixes #283
Summary
Architect used a fixed 50 ms idle sleep in the main loop, which meant a keypress or other visible event could land just after the loop went idle and then wait for that sleep to finish. This changes the frame loop to compute an explicit wait strategy, use
SDL_WaitEventTimeout(...)while idle, keep the existing active pacing rules, and let the notification thread wake the runtime immediately by posting a custom SDL event after it queues external updates.Testing
zig buildzig build testjust lintTest plan