Investigating macOS input-to-display latency

Ruling out the editor ⋅ The difference follows the display refresh rate ⋅ Other applications ⋅ Investigating the launch context ⋅ Moving the mouse makes applications faster ⋅ Looking at WindowServer and Core Animation ⋅ Where is the additional latency? ⋅ Reproducing the issue ⋅ What’s next?

I recently noticed something strange while running typing-latency benchmarks for Koi (now Peeknext).

The editor had previously measured very well, but newer measurements were consistently worse. I initially assumed I had introduced a regression somewhere.

After investigating Qt, Scintilla, code signing, and various build configurations, I eventually discovered something unexpected.

The exact same application was significantly faster when launched directly from Apple Terminal than when opened normally through macOS.

For example:

open -n /Applications/Koi.app

Compared with:

/Applications/Koi.app/Contents/MacOS/Koi

Same executable, same application bundle, same display, and same benchmark.

I still haven't identified the exact mechanism, but I've reproduced the behavior in several unrelated applications, on two Macs, and across macOS Sequoia and Tahoe.

Ruling out the editor

I initially investigated several possible causes:

  • Qt input-method handling and accessibility
  • QScintilla rendering and repaint regions
  • Code signing and build configurations
  • Application-side paint times

None explained the difference.

I then built a minimal Qt application using QPlainTextEdit:

import sys

from PyQt6.QtWidgets import QApplication, QPlainTextEdit

app = QApplication(sys.argv)

editor = QPlainTextEdit()
editor.resize(1200, 800)
editor.show()

sys.exit(app.exec())

I packaged it as a normal .app bundle using py2app. The same difference appeared.

This ruled out most of Peeknext's implementation, including its custom Scintilla fork.

The difference follows the display refresh rate

At 60 Hz, the minimal Qt application measured:

Launch method Average P95 P99
Open normally 29.676 ms 37.742 ms 43.080 ms
Direct Mach-O 16.404 ms 20.500 ms 24.882 ms

The P95 difference was 17.242 ms. One refresh interval at 60 Hz is 16.667 ms.

At 100 Hz:

Launch method Average P95 P99
Open normally 24.687 ms 31.182 ms 33.797 ms
Direct Mach-O 16.295 ms 20.623 ms 23.286 ms

The P95 difference was 10.559 ms. One refresh interval at 100 Hz is 10 ms.

The difference closely follows one display refresh interval.

This suggests that the slower application might be missing a presentation opportunity and reaching the display one frame later.

I haven't confirmed that directly.

Other applications

I repeated the experiment with several editors.

On a MacBook Air M4 running macOS Tahoe 26.6.1:

Application Open P95 Direct p95
Peeknext 39.924 ms 25.635 ms
BBEdit 38.176 ms 22.685 ms
Xcode 40.122 ms 27.233 ms
Sublime Text 56.696 ms 34.390 ms

Xcode and Zed also reproduced the behavior on a Mac mini M2 Pro running macOS Sequoia 15.7.5.

Different applications, rendering implementations, hardware, and macOS versions.

This doesn't appear to be specific to Peeknext or Qt.

Investigating the launch context

Direct executable execution alone wasn't enough to explain the difference.

  • Apple Terminal: Fast.
  • Ghostty: Slow.
  • SSH to localhost: Slow.
  • Apple Terminal, fork, exec: Fast.
  • LaunchServices, exec: Slow.

The fast state also survived terminal detachment and Unix session changes.

I compared several aspects of the resulting processes:

  • RunningBoard management and spawn roles
  • Process coalitions
  • Jetsam priorities
  • Environment variables and bundle identifiers
  • Process and Mach task QoS
  • AppKit activation state

Normally launched applications were managed by RunningBoard and received their own application coalitions.

Applications launched directly from Apple Terminal inherited Terminal's coalitions and weren’t managed as RunningBoard application jobs.

However, applications launched from Ghostty also inherited their launcher's coalitions, while remaining slow.

I attempted to create a separate coalition from the fast Terminal context, but macOS rejected the operation with Operation not permitted.

These differences are interesting, but I haven't established which, if any, causes the latency difference.

Moving the mouse makes applications faster

While running the benchmarks, I noticed something even stranger.

Moving a physical mouse appeared to reduce input-to-display latency.

Not clicking anything. Just moving the mouse.

On the Mac mini at 100 Hz:

State Average P95 P99
Mouse moving 14.656 ms 18.030 ms 23.509 ms
Mouse idle 27.446 ms 36.406 ms 38.112 ms

That's an 18.376 ms difference at P95.

The effect appeared quickly and disappeared when the mouse stopped moving.

I reproduced it on the MacBook Air too.

Interestingly, trackpad movement didn't produce the same result. Neither did synthetic mouse events or cursor warping.

I also disabled the association between physical mouse movement and cursor position using:

CGAssociateMouseAndMouseCursorPosition(false)

The cursor remained stationary, but the latency improvement persisted. So the effect doesn't require visible cursor movement.

I tried several other ways of keeping the application or display system active:

  • Continuous Qt timers and repaint requests
  • AppKit event polling and window updates
  • Synthetic mouse movement
  • Increased GPU activity
  • NSProcessInfo latency-critical activity

None reproduced the physical mouse result.

Looking at WindowServer and Core Animation

Using System Trace, I observed substantially more WindowServer, NSEvent, and Core Animation activity during physical mouse movement.

But increased activity alone doesn't explain the results.

Applications launched from Apple Terminal were already fast with the mouse idle, even when Core Animation activity was relatively sparse.

There appear to be at least two ways to reach the lower-latency state:

  1. Launch from a process context that produces the faster behavior.
  2. Move a physical mouse while an otherwise slower application is running.

The first persists after launch. The second changes dynamically.

Both produce a similar reduction in externally measured input-to-display latency.

Where is the additional latency?

I instrumented Peeknext's paintEvent() directly.

Paint times were typically below 1 ms, and both launch methods painted equivalent regions.

The additional delay wasn't visible in application-side measurements.

The benchmark uses Keypress.sh, which measures actual input-to-visible-pixel latency rather than application event handling.

The approximate path is:

Keyboard input
    |
Application event processing
    |
Document update
    |
Application painting
    |
AppKit / Core Animation
    |
WindowServer
    |
Display presentation
    |
Visible pixel change

The refresh-rate measurements suggest that the slower application might reach the display one presentation opportunity later.

Conceptually:

Fast:
    Input → Paint → Presentation N

Slow:
    Input → Paint → Presentation N+1

This remains a hypothesis.

I haven't directly observed the corresponding presentation sequence or identified whether the delay occurs in Core Animation, WindowServer, display presentation, or elsewhere.

Reproducing the issue

The minimal Qt application above is sufficient to reproduce the launch-context difference in my tests.

Package it using py2app, then compare:

open -n dist/QtLaunchTest.app

With:

dist/QtLaunchTest.app/Contents/MacOS/QtLaunchTest

Launch the second command from Apple Terminal.

I used Keypress.sh for the measurements, with 200 input events per benchmark run.

The behavior is worth testing at different fixed display refresh rates and with different terminal emulators.

What’s next?

I haven't found the exact mechanism yet.

The most promising areas to investigate are Core Animation transaction timing, WindowServer presentation scheduling, and inherited process state.

In particular, I'd like to identify when an application update is committed and when it becomes eligible for presentation.

The physical mouse result might provide a more direct way to isolate the mechanism, since the behavior changes dynamically without restarting the application.

For now, the measurements suggest a difference somewhere in macOS presentation or frame scheduling rather than application-side rendering.

What started as a suspected Peeknext performance regression has turned into an investigation of how macOS schedules application updates for display.

And apparently, moving a mouse can make a text editor significantly faster?