inputlatency

command
v0.1.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Command inputlatency measures how long input takes to show on screen in native UI on macOS: from when an event arrives to when the frame showing it reaches the display. It needs a desktop session.

go run ./internal/inputlatency [-mode type,scroll,drag,anim] [-runs 8] [-events 300]

Each run is a process of its own with a window of native UI, shown without activating the app, so it takes neither the keyboard nor the front: typing into a text area (a key every 60 to 140 ms, each frame after a pause), scrolling a list of a million rows with the trackpad (an event every 4 to 12 ms), dragging a box (the same), or animating a box with no input (anim), or boxes casting wide shadows (30, -boxes), which keep the GPU busy (heavy). Events come from another goroutine through the main run loop, as the window server's do, at any time within the display's refresh, and go through the window as AppKit's (sendEvent:, scrollWheel:); an event is taken to arrive when it is posted, so the time the main thread was busy counts.

The frame showing an event is the next one the main thread presents after handling it: the main thread handles events and builds frames in turn. Its drawable's presented handler gives when it reached the screen (presentedTime). The tool swizzles the presents (the command buffer's presentDrawable:, the drawable's present), -[CAMetalLayer nextDrawable] for the main thread's waits, and the surface view's goletTick: and updateLayer (internal/darwin) for when frames start, and fails if they are gone.

Each run prints the latency's mean and percentiles in milliseconds, and the means of what it is made of: waiting for the main thread (queue), handling the event (handle), from then to the frame's present (waiting for the display link's next tick, or the end of the run loop's pass after a pause, building and painting, waiting for a drawable), and from the present to the screen (the GPU, the window server's composite and the display). And of the frames: how long the main thread waited for drawables a frame, and how often more than 4 ms; what share of the refreshes showed a new frame (all of them for -mode anim, an animation with no input, but for frames not drawn in time); and what share of the frames presented never showed, replaced by the next. The summary gives the median of the runs' figures: a run keeps the state the window server settles in, which changes from run to run, so compare medians of several runs, alternating builds.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL