Skip to content

Replace idle sleep with a wakeable SDL wait#286

Merged
forketyfork merged 2 commits intomainfrom
feat/wakeable-idle-wait
Apr 13, 2026
Merged

Replace idle sleep with a wakeable SDL wait#286
forketyfork merged 2 commits intomainfrom
feat/wakeable-idle-wait

Conversation

@forketyfork
Copy link
Copy Markdown
Owner

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 build
  • zig build test
  • just lint

Test plan

  • Leave Architect idle for a few seconds, then type in a focused terminal and confirm input appears immediately instead of feeling delayed by the old idle sleep window.
  • Trigger an external session status notification while Architect is idle and confirm the status highlight updates right away.

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.
@forketyfork forketyfork marked this pull request as ready for review April 13, 2026 09:31
@forketyfork forketyfork requested a review from Copilot April 13, 2026 09:31
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 uses SDL_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.

Comment thread src/platform/sdl.zig Outdated
Comment thread src/app/runtime.zig Outdated
Comment thread src/session/notify.zig Outdated
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.
@forketyfork forketyfork merged commit 4a0df45 into main Apr 13, 2026
4 checks passed
@forketyfork forketyfork deleted the feat/wakeable-idle-wait branch April 13, 2026 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Replace idle sleep with a wakeable event wait to reduce typing latency

2 participants