Skip to content

perf(recording): take the cursor position from the recorder's mouse sample - #2621

Open
celeroncoder wants to merge 1 commit into
CapSoftware:mainfrom
celeroncoder:perf/cursor-reuse-mouse-sample
Open

celeroncoder wants to merge 1 commit into
CapSoftware:mainfrom
celeroncoder:perf/cursor-reuse-mouse-sample

Conversation

@celeroncoder

@celeroncoder celeroncoder commented Oct 15, 2026 •

Copy link
Copy Markdown

spawn_cursor_recorder keeps one DeviceState and reads get_mouse() from it every tick (about 60/s) for the buttons. It then called RawCursorPosition::get() for the position, which is DeviceState::new().get_mouse().coords. So every tick built a second DeviceState and queried the pointer twice.

What that extra DeviceState::new() costs:

  • Linux (X11): XOpenDisplay + XCloseDisplay, so one X connection set up and torn down per tick.
  • macOS: device_query assert!s application_is_trusted_with_prompt(), so the Accessibility trust check ran every tick.
  • Windows: a second GetCursorPos plus the button polls.

Change

  • Adds RawCursorPosition::from_coords (crates/cursor-capture/src/position.rs). get() calls it and keeps working for the cap-cursor-capture binary.
  • spawn_cursor_recorder builds the position from the MouseState it already has, in all three places: the initial sample, the waiting-for-start-gate branch and the per-tick sample.
 let mouse_state = device_state.get_mouse();
-let position = cap_cursor_capture::RawCursorPosition::get();
+let position = cap_cursor_capture::RawCursorPosition::from_coords(mouse_state.coords);

Positions come from the same source as before. On Linux both handles run XQueryPointer on the default root of XOpenDisplay(NULL). On macOS and Windows DeviceState is a unit struct and the position is readmouse::Mouse::location() / GetCursorPos. The only difference is that position and buttons now come from one sample instead of two taken microseconds apart.

Results (Linux X11)

main @ 83237e9 This PR @ b4f88a6
X11 connect() per tick, moving pointer 2.00 (926 over 463 ticks) 1.00 (504 over 504 ticks)
Recorder CPU per 10 s, idle pointer, 24 px ARGB cursor 259 ms [240-270] 166 ms [160-185]
Recorder CPU per tick, moving pointer, 24 px ARGB cursor 414 µs [407-470] 266 µs [265-269]
Xvfb CPU per 10 s, idle pointer, 24 px ARGB cursor 240 ms [220-260] 140 ms [140-150]

The real spawn_cursor_recorder ran for 10 s from release builds of both commits against Xvfb 1920x1080 on a shared 2 vCPU aarch64 VM. CPU is the recorder's user+sys from getrusage, median of 5 interleaved runs with the range in brackets. Connection counts come from one strace run, with the startup connections subtracted.

  • Most of the saving is sys time. At 24 px idle, recorder sys went from 168 to 91 ms per 10 s and user from 91 to 75 ms.
  • The idle runs shared the VM with a background build (load1 1.13-3.74). The moving runs were at load1 0.20-0.96.
  • Xvfb is a local server with no compositor, so a real X.Org or XWayland session will show different absolute numbers.
  • With the pointer stepped through 8 fixed positions, both builds recorded the same 8 pixel positions and the same cursors.

macOS and Windows weren't built or measured. The code there is the same platform-neutral change, and on macOS it removes the per-tick Accessibility check.

Overlap

How this was made

This PR is agent-generated.

  • Gemini 4 Argon (Antigravity) and space-bunny-free (OpenCode) found this during an audit of the repo and wrote the first patch.
  • Claude Opus 5.5 reviewed that patch, rewrote it on current main and took the measurements above with a probe that drives the real recorder.
  • Gemini 4 Argon reviewed the final diff and numbers over two rounds and approved it.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable issues were found.

Summary

The recorder now takes cursor coordinates from its existing mouse sample instead of creating another DeviceState.

  • The cursor recorder gets positions from its existing mouse sample.

Reviews (1) · Last reviewed commit: "perf(recording): take the cursor positio..." · Reviewed by Greptile

@vercel

vercel Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

@celeroncoder is attempting to deploy a commit to the Cap Software Inc Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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