Repository navigation
Description
Part of #49; builds on #50 and #52.
What
Today a live resize stays in step for free. windowDidResize: calls into JS synchronously, and react-x11 lays out, paints and presents inside that call (CocoaApp._routeGeometry → _afterInput), so the new frame and the moved edge commit together.
In threaded mode the event crosses to the worker and the frame comes back later. Without a handshake the edge moves first and the content catches up a frame or more behind.
Every platform has a handshake for this: Wayland's configure/ack_configure, X11's _NET_WM_SYNC_REQUEST. Flutter's Windows embedder waits up to 100 ms in WM_SIZE for a frame of the new size. react-x11's Windows PRD makes one (docs/windows.md §"Resize: where the threads meet"), and so does this.
Proposed (mechanism only)
native.setResizeHandshake(window, { waitMs }) // 0 turns it off
native.txCommit({ width, height }) // a frame batch says what size it was painted at
- In
windowDidResize:the UI thread publishes the new content rect and emitswindow-resize { live }. It then waits on the command queue's condition variable, bounded bywaitMs, for a frame batch tagged with that size. It applies that batch inline, so the frame lands in the same transaction as the resize, then returns to AppKit. - It must drain inline rather than wait for the run-loop source. The resize tracking loop calls the delegate outside any run-loop pass: in the probe,
CFRunLoopCopyCurrentModeanswered NULL there, and 44 batches were applied from inside the handshake itself. - JS never waits on the UI thread, so the wait cannot deadlock. The worst case is the deadline.
- A missed deadline shows the last frame at its old size. The newly exposed edge shows the root layer's
backgroundColor, the window's background colour already set throughcreateWindow2, rather than garbage.
Measured (probe code in #49)
- 50 ms budget, 3 ms of simulated layout per tick in the worker.
- Posted-event live resize: all 39 ticks were live (
inLiveResizetrue) and all 39 met the wait. The UI thread waited 3.1 ms p50, 4.4 ms max. - 30 programmatic
setFrame:display:steps: 30 of 30 met, 3.1 ms p50, 3.5 ms max. That is the layout time plus about 0.1 ms of crossing each way.
Not measured: a hardware resize, or a tree that misses the deadline. react-x11's Cocoa resize cell costs 28 ms a tick at 3,662 nodes, so large trees will miss, and what shows then is the part to get right.
Consumer
react-x11 CocoaApp geometry routing and liveResizing (src/nodes/window/size.js defers the content floors); docs/macos.md §"JS on a worker: a UI thread of the bridge's own", sidorares/react-x11#539.
Activity
feat: the live-resize handshake — a bounded wait for a frame at the n…