I drive a Windows PC from a Linux VM over SSH. Every action used to open a fresh SSH tunnel, run one command, and tear it down. A single status check cost 5 to 7 seconds. A short sequence of actions cost a minute. The work was slow, not the PC.

The fix was boring. One persistent tunnel, reused for everything.

What changed

Before: each call opened its own tunnel (ssh -N -L ...), waited a fixed 4 seconds for it to come up, ran one request, and closed it.

After: one tunnel process, started on demand, kept alive with a restart loop. Readiness is a TCP poll on the local port, not a fixed sleep. The client keeps one process and runs many requests through it in script mode.

Two more cuts came with it. The status response was a full UI automation dump, several kilobytes of noise. Now it returns interactive elements and text only. And the client batches: one process, many requests, instead of one process per request.

Measured, not guessed

Ping through the tunnel: 0.41s. A state read: about 1.1s. The old client took about 5.3s for a ping and 5 to 7s per state call. Roughly 5 to 10x faster, depending on the call.

A real sequence (type in Notepad, select all, read the text back) went from a median of 17.29s with the old per-action loop to 7.69s batched, and 7.06s with the chunked runner. The remaining time is paced typing and app waits, not transport.

The part that actually matters

The tunnel is the expensive piece, not the work. SSH handshake plus TCP setup plus a fixed sleep dominated every call. Once the tunnel stays up, the calls themselves are cheap.

If your remote automation feels slow, check what you pay per call before you optimize the calls. One persistent connection, readiness by poll instead of sleep, and the smallest response you can get away with. That was the whole change.