Repository navigation
Description
Summary
On macOS, GpuixRenderer.tick() can spend most of its time inside the embedded AppKit pump even when GPUI drawing is cheap. A Bun process that owns a continuously producing PTY then falls behind because PTY callbacks, timers, promises, and sockets cannot run while tick() is waiting for the next native wake.
Tested against @gpuix/[email protected] / @gpuix/[email protected] on Apple Silicon with Bun 1.4.0.
Reproduction and measurements
The reproducer uses a real GpuixRenderer, an 8 ms startFrameLoop, a real Bun PTY, and a deterministic DEC 2026 truecolor framebuffer producer.
With the current blocking pump, an 800×600 run measured approximately:
- 15.6 ms median
tick()latency; - 93% of wall time inside
tick(); - 23 PTY/service/native-stage frames per second;
- about 0.30 ms GPUI draw p90.
The renderer was not the bottleneck; the JavaScript producer and PTY delivery were starved by the embedded pump.
A nonblocking drain on a fullscreen 1470×923 logical window (185×53 terminal grid) measured:
- 58.7 PTY callbacks, service frames, and native stages per second, all 1:1;
- 0.029 ms median / 0.064 ms p90
tick()latency; - 0.50% wall time inside
tick(); - 0.13 ms GPUI draw p90;
- zero React commits during animation.
Proposed direction
For embedded polling, drain only work that is ready now:
- dequeue pending NSEvents with
distantPast, bounded by a safety cap; - dispatch those events and call
updateWindows; - run ready CoreFoundation sources with
CFRunLoopRunInMode(..., 0.0, true); - return control to Bun without entering
NSApplication::run().
If changing the semantics of the existing embedded tick is too broad, a separate nonblocking poll API would also solve the integration problem.
Reference implementation
No PR is being opened, per the external-contributor policy.
- Branch: https://github.com/monotykamary/zed/tree/reference/gpuix-render-pipeline
- Focused commit: monotykamary/zed@8324530
- GPUix integration reference: https://github.com/monotykamary/gpuix/tree/reference/heddlework-native-primitives
Validation
- GPUix native suite: 227 passed
- GPUix React suite on the integration build: 377 passed
- Downstream application suite: 319 passed
- Fullscreen live PTY/native/GPUI telemetry as reported above
Would a nonblocking embedded poll be acceptable in gpui_macos, and should it replace the current tick behavior or be exposed separately?
Activity
gpui_macos: keep embedded event pumps nonblocking
Use nonblocking embedded AppKit event pumping
Document nonblocking macOS AppKit ticks and add a regression test.
release: @gpuix/[email protected] and @gpuix/[email protected]
Drive the macOS frame loop from GPUI's display link instead of an 8 m…
A bounds or scroll read is a layout-only pass that paints nothing: th…