Designs
Page 5 of 8 · Instant chat

A sent message should show at once and the reply should arrive as it is written

In progress. The bubble-on-tap change and the forward read are open pull requests.

The answer

Sent messages should show at once, and replies should cost only what is new

Status: in progress. Two changes are open for review and the numbers so far are from the clean link only. The tests on the slow links are still running.

Today a sent message shows up about a quarter second after you tap, and the words sit in a greyed box until then (M). On a slow link it should be worse (C). A new reply line makes the phone download about 51 KB of history again (M).

The phone already saves every sent message in its outbox first, so nothing is lost if the link fails. The message bubble can come straight from the outbox, with no wait for the machine.

256ms
from tap to a visible message, clean link, today
Measured
53KB
downloaded for one 200-byte reply line, today
Measured

The tiles are the starting point. The sections below explain where each number comes from and what changes.

Sending

Three waits sit between your tap and the message appearing

We read the code for what happens after the tap. Three things delay the bubble, and a fourth hides it:

  1. A wait of up to 1 second
    The phone first waits for an unsent draft edit to finish. On a slow link that edit is usually still in flight (G, from reading the code).
  2. A label that says the wrong thing
    The row says Saved on this device, waiting for connection, even while it is sending.
  3. The row vanishes, then returns
    When the machine answers, the outbox row is deleted. It comes back only after a full re-read.
  4. The words stay in the box
    The box stays full and disabled until the machine answers, which can take up to 20 seconds.

The fix is mostly re-ordering, not a new system. Draw the row first, empty the box, and then wait. Keep the row until the machine's own record has the same id, so it never blinks away.

With the link blacked out for 30 seconds before the tap, the message appeared only 30.5 seconds later, with the words still stuck in the box (M).

Receiving

Each new reply line makes the phone download the whole recent history

The daemon sends the phone a nudge, "something changed", with no text in it. The phone then re-reads the last 200 events, because a change in the last line changes the whole tail. How big is that for one line?

Downloaded per new reply line
Daemon to phone. Clean link, unchanged app.
A 200-byte line
53 KB
A 4 KB line
57 KB
A 40 KB line
107 KB
Show as table
KB
A 200-byte line53
A 4 KB line57
A 40 KB line107

Measured on the clean link. The slow-link rows are still running.

A tiny 200-byte line costs 53 KB, 265 times its size (C). A 20-line turn cost 1,276 KB. After a 30-second blackout, all 10 missed lines (23 KB) appeared 2.0 seconds after the link returned, but 554 KB was resent, 24.3 times what was missed (M).

The fix is a forward read: the phone asks only for records after the last byte it already has. The daemon answers with whole records and says where it ended. A stale file token gets a clear "start over" answer.

The plan

Five pull requests remain, and one idea was dropped for something better

The plan started with six pull requests. It changed once, because the harness-link design arrived.

The pieces and where each stands. Open ones: the bubble on tap, pull request 2777; the forward read, pull request 2778.
PieceWhat it doesStatus
Measure firstChat rows in the slow-link rigClean link done, rest running
Bubble on tapMessage shows at once and staysOpen for review
Agenda labelsSending and Sent wordingNot started
Forward readRead only what is new, by byteOpen for review
Reply streamA separate socket for reply textDropped
After numbersRe-run the same rowsWaiting

The bubble-on-tap change is pull request 2777. The forward read is pull request 2778. Both are open for review. The forward read also needs a security review, because its route reads masked content.

The separate reply stream was dropped. The harness-link design carries replies on one sync stream per phone instead, and reuses the forward read as its cursor.

Limits

Replies still arrive record by record, not word by word

Predicted gains (C): a new line should reach the phone in about 1 second instead of about 5 on the middle link, and about 1.8 seconds instead of about 16 on the worst link.

Those are computed from the link speeds and a guessed 100 KB tail (the measured tail is about 51 KB), not measured. The reply gains also need the harness-link sync stream, which is not built. The two open pull requests cover the send rows and the forward read only.

The agent writes its transcript one whole record at a time. So reading the transcript can give record-by-record text, never word-by-word. Word-by-word streaming needs the protocol channels from the harness-link design. The wire format leaves room for it later without a change.

What we did not test is just as important:

  • The send and reply rows on the middle and worst links: still running.
  • A real phone on a real network.
  • Several phones watching one ferret at once, which repeats the same work (a known cost).