Skip to content

perf(platform): macOS reads the monotonic clock through mach_absolute_time - #114

Merged
phobos665 merged 1 commit into
mainfrom
perf/macos-clock
Nov 2, 2026
Merged

phobos665 merged 1 commit into
mainfrom
perf/macos-clock

Conversation

@phobos665

Copy link
Copy Markdown
Owner

On macOS, GetTickCount64 and QueryPerformanceCounter now read mach_absolute_time instead of clock_gettime(CLOCK_MONOTONIC). On Apple Silicon that is 5 ns a read instead of 17 ns. Clock reads were 7.5% of Constantine's main thread.

The kernel-call summary in kernel_thunk_dispatch also used to read the clock on every kernel call to see whether two seconds had passed. It now reads it once every 256 calls.

Measurements

Apple M4, muted runs in the background. "Work per frame" is the "rest of frame" figure from the swap timing line.

Title Main This branch
Constantine, capped 4.20 ms 3.92 ms
Constantine, uncapped ~97 fps ~97 fps

TimeSplitters 2 stays at 60 capped on both builds. Uncapped it sits at exactly 120 fps on both, so neither run can show a difference.

Scope

  • Windows and Linux are unchanged. The new clock path is inside #if defined(__APPLE__), and other POSIX hosts keep clock_gettime.
  • The every-256-calls summary check applies on every host. It only changes how often the two-second summary checks the time, not what it prints.

…_time

GetTickCount64 and QueryPerformanceCounter called clock_gettime, 17 ns a
read on Apple Silicon against 5 ns for mach_absolute_time, and the clock
reads were 7.5% of Constantine's main thread. The kernel-call summary also
reads the clock every 256 calls instead of every call.

Constantine capped: 4.20 -> 3.92 ms of work a frame; uncapped unchanged.
@phobos665
phobos665 merged commit c2656e1 into main Nov 2, 2026
5 of 7 checks passed
@phobos665
phobos665 deleted the perf/macos-clock branch November 2, 2026 15:11
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.

1 participant