Skip to content

perf(cua-driver): reuse one session-bus connection for the GNOME helper - #4879

Merged
f-trycua merged 4 commits into
mainfrom
perf/cua-driver-gnome-dbus-transport
Oct 8, 2026
Merged

f-trycua merged 4 commits into
mainfrom
perf/cua-driver-gnome-dbus-transport

Conversation

@f-trycua

@f-trycua f-trycua commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

What

On GNOME Wayland every call to the WinRects helper (org.cua.WinRects) spawned a gdbus subprocess and polled it for exit. Owner attestation alone (GetNameOwner, GetConnectionUnixProcessID, GetConnectionUnixUser, plus GetVersion when gated) costs three or four of those before the real call, and a live window preview pays that on every frame.

This replaces the subprocess with a persistent transport (wayland/shell_helper/transport.rs):

  • One connection: a single zbus session-bus connection on a dedicated one-thread Tokio runtime. Synchronous callers, including those already inside Tokio, block on a channel, so runtimes never nest.
  • Typed bodies: each method's arguments are encoded as their D-Bus types. No string is ever interpreted as shell or GVariant text.
  • Same reply shape: replies keep the textual shape the existing parsers read, ('…',) and (uint32 N,). GetRects now arrives as raw JSON, which the […] extraction already handles and which avoids gdbus quoting of titles with apostrophes.
  • Reconnect policy: a timeout or transport error drops the connection and the next call reconnects. A call is never replayed, so a mutation such as Activate cannot apply twice. An error reply keeps the connection, for example no helper on the bus or a refused argument. This split is new relative to T3's version, which reconnected after any failure, including every call on a machine without the helper.

Related: #4809. Because GetRects now arrives as a typed string, this also fixes the bug #4809 reports. gdbus's GVariant text adds a second layer of escaping, so an apostrophe or quote in any window title made the whole snapshot unparseable and hid every window. The test serves a title with an apostrophe, quotes, a backslash, a newline and non-ASCII, and checks that parse_windows and parse_window_origin still find every window.

wait_timeout and the gdbus plumbing are removed. Owner attestation and the unique-name addressing are unchanged.

Credit

Ported from T3 Code's Linux patch to Cua Driver 0.34.0: pingdotgg/t3code#16975, patches/cua-driver-linux/0.34.0.patch. T3 Code is MIT-licensed, Copyright (c) 2026 T3 Tools Inc. T3 measured window capture at 381 → 58 ms with this transport. The THIRD_PARTY_NOTICES row comes with #4877 and is extended here once that merges.

Testing

typed_roundtrips_on_one_private_connection starts a private dbus-daemon and serves a fake helper. It checks:

  • repeated calls on one connection;
  • the reply shapes, including the apostrophe title;
  • Capture decoding;
  • that error replies and malformed arguments return Failure::Reply;
  • that the connection keeps working afterwards.

It skips if dbus-daemon is not installed. Linux CI runs it.

Linear: CUA-1235 (tracking CUA-1233)

🤖 Generated with Claude Code

Every WinRects call spawned a gdbus subprocess, and owner attestation
alone makes three D-Bus calls before the real one. A live preview pays
that on every frame. Replace the subprocess with one zbus connection on
a dedicated single-thread Tokio runtime, so callers inside or outside
Tokio can block on it without nesting runtimes.

Bodies are typed on the wire, and replies keep the textual shape the
existing parsers read (GetRects now arrives as raw JSON, which also
avoids gdbus quoting). A timeout or transport error drops the
connection and the next call reconnects; a mutation is never replayed.
An error reply, such as no helper on the bus, keeps the connection.

T3 Code measured window capture going from 381 ms to 58 ms with this
transport. Ported from their Linux patch to Cua Driver 0.34.0
(pingdotgg/t3code#16975, MIT, Copyright (c) 2026 T3 Tools Inc.); the
reply-versus-transport split is new here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cursor
cursor Bot requested a review from ddupont808 as a code owner October 8, 2026 13:23
Parse the typed GetRects reply as raw JSON instead of slicing a bracket
span, and reuse that parser for focus. Salvaged from #4809, including
the malformed-snapshot fixtures and the Nix dbus check input.

Co-authored-by: injaneity <44902825+injaneity@users.noreply.github.com>
@cursor
cursor Bot force-pushed the perf/cua-driver-gnome-dbus-transport branch from 4d98119 to 0d0c5f7 Compare October 8, 2026 13:45
dbus-daemon --session needs the system session.conf, which the Nix
build sandbox lacks; the daemon then exits without an address. Write a
minimal session config listening in a temp dir instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@f-trycua
f-trycua merged commit 48cc491 into main Oct 8, 2026
58 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants