Repository navigation
Conversation
macOS ignored `swap_interval`. Each frame waited for the next tick of a `CVDisplayLink`, Metal presented each drawable on a vertical blank, and an occluded window slept between frames to save power. So frames could never come faster than the display refreshes, as a tool drawing frames off-screen to save them needs, or a benchmark. With `swap_interval: Some(0)`, a frame now starts as soon as the last one is done: there's no frame pacer, the Metal layer doesn't sync to the display, and a hidden window isn't slowed down, as on Windows and Linux, where `Some(0)` turns vsync off and nothing slows a hidden window. Any other value keeps to the display's refresh rate, as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: multica-agent <github@multica.ai>
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.
Why
macOS ignores
swap_interval, and three things keep its frames to the display:CVDisplayLinkbefore each frame.perform_redrawso it draws at most 60 frames a second.So on macOS nothing can draw faster than the display refreshes. A tool that draws frames off-screen to save them needs to, and so does a benchmark. On Windows and Linux,
swap_interval: Some(0)sets a swap interval of 0, and nothing slows a hidden window.Change
With
swap_interval: Some(0)on macOS:displaySyncEnabledis off (OpenGL's swap interval is already 0);Any other value,
Noneincluded, keeps to the display's refresh rate, as before. The doc comment onswap_intervalsays so.A macroquad game (CHOMP) has a capture mode that plays a level and saves its frames, drawn into render targets, and its window shows nothing. With this, #693 and not-fl3/macroquad#1081, its frames no longer wait for the display.
Measurements
These are the capture's times for 2,400 frames, saving 8 of them, on an M2 Max with a 120 Hz screen. Every frame came out byte-identical:
clear_screen: falseOn Metal, this alone makes no difference while the frame still takes a drawable. The display only lets go of drawables at its own pace, with display sync on or off: 22.3 s before and 22.8 s with this, at a load average of 190 to 330.
Verification
cargo checkpasses foraarch64-apple-darwin,aarch64-apple-iosandx86_64-unknown-linux-gnu.🤖 Generated with Claude Code