Skip to content

Compress Mirror traffic from the Host - #1161

Merged
onevcat merged 2 commits into
mainfrom
feat/mirror-wire-compression
Nov 22, 2026
Merged

onevcat merged 2 commits into
mainfrom
feat/mirror-wire-compression

Conversation

@onevcat

@onevcat onevcat commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Summary

Mirror messages were uncompressed. While the iOS app is open, the Host sends the full pane list every 3 seconds: about 40–60 KB per minute (about 3 MB per hour) on the phone's own logs. 096 may carry this traffic through our relays, where every byte costs.

New capability deflate-v1 (docs-ai 097):

  • The Host lists deflate-v1. A client that sees it sends compress once, right after the first panes; from then on the Host sends every packet as kind 3: the next part of one raw DEFLATE stream per connection, one message per sync flush. Because the stream keeps its window, a pane list that barely changed costs a few dozen bytes instead of 2.2 KB.
  • iOS roster and pane connections and the Mac client ask for it. Clients never compress what they send.
  • Old clients (iOS before this, Android) and old Hosts keep exchanging plain packets.
  • An inflate error, a nested kind 3, or more than the existing 8 MB message limit after inflating closes the connection.
  • System zlib, no new dependency. Shared code in Mirror/Shared/MirrorWireCompression.swift.
  • Wire spec in docs/remote-mirror-wire.md, with a vector made by another zlib (Python) for the Android client to check against.

Device measurement

iPhone One against one isolated Debug Host with 5 panes, first with the iOS build from main, then with this build; Host bytes sent, from nettop:

Scenario Plain Compressed Change
Idle on the agents list, per minute 59,194 B 3,465 B −94%
Opening a terminal pane (6 s, roster included) 13,309 B 4,280 B −68%
22 s of terminal output 106,357 B 10,547 B −90% (repeated output)

The terminal rendered normally with compression. A chat open was not measured on the device; conversation event JSON compresses 3.7–4× in gzip.

Tests

  • New MirrorWireCompressionTests (Mac): the other zlib's vector; a stream round trip over all payload kinds with repeated lists shrinking; plain payloads pass through without a stream; corrupt, nested and oversized (a 1 MB zero block) payloads are rejected.
  • New Host test: through a real paired connection, every reply after compress arrives compressed, asking twice is harmless, and a client that never asks gets plain packets.
  • iOS: the vector; the roster and pane connections ask once, before anything else, and only a Host with the capability.
  • make check, make test, make test-mirror-ios-unit (226): pass.
  • MirrorHost.handle was split slightly (refresh, writeInput) to stay within the complexity limit; no behavior change.

@onevcat
onevcat merged commit 2d0488d into main Nov 22, 2026
3 checks passed
@onevcat
onevcat deleted the feat/mirror-wire-compression branch November 22, 2026 15:20
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