Skip to content

perf(session): rebuild transcript time stamps once a minute while streaming - #236

Merged
Tarquinen merged 2 commits into
devfrom
timestamps-per-minute
Nov 21, 2026
Merged

Tarquinen merged 2 commits into
devfrom
timestamps-per-minute

Conversation

@Tarquinen

@Tarquinen Tarquinen commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

While a reply streams, the transcript's time stamps, and the whole entry list built with them, were rebuilt on the main thread once a second. Stamps only show minutes, so now they're rebuilt once a minute, or once a second while the last prompt reads as now: it has no time of its own, or it comes from a server clock ahead of the phone's (where a pause stamp can appear on any second). Nothing visible changes. Ports the stamp part of iOS #300 (4c26741a); checking the skewed-server case is Android-only.

On the VM's JVM (not a phone), the once-a-second rebuild took 0.24 ms at 1,000 rows and 1.5 ms at 6,000 rows, against 14–95 µs for a normal streamed batch.

Verified: ported iOS stampsRebuildOnTheMinuteNotTheSecond (the one rebuild lands on second 60), plus tests for an untimed prompt and a skewed server's pause stamp; dev's logic fails them. Full scripts/check.sh on the Android VM.

The projection cache keyed its time stamps on the current second, so
while a reply streamed, the first batch of every new second missed the
streaming fast path and rebuilt every entry, the stamps and the
new-messages mark on the main thread. Stamps only show minutes (and
Today turns into Yesterday on a minute), so the key is now the minute,
or the second while the last prompt has no time of its own and may
read as sent now. Ports iOS #300 (4c26741a).

Measured on the VM's JVM with real-format IDs: a streamed batch costs
14-95 us; the once-a-second rebuild cost 0.24 ms (1,000 rows) to
1.5 ms (6,000 rows). That rebuild now happens once a minute.

Verified: ported iOS stampsRebuildOnTheMinuteNotTheSecond into
TranscriptBenchmarkTests (70 one-second batches rebuild once); it fails
on dev's code. Full scripts/check.sh on the Android VM.
A server whose clock is ahead of the phone's mints prompt IDs that read
as now. While that lasts, the prompt's pause stamp can cross its
one-hour threshold on any second, and keying by the minute held it back
until the next minute. Such a prompt now keys by the second, like an
untimed one; this differs from iOS, which only checks untimed prompts.

Tests: the stamp tests move to their own Robolectric class
(TranscriptStreamWorkTests, same file) so the two older tests stay plain
JVM. The rollover test asserts the one rebuild lands on second 60; new
tests cover an untimed last prompt (rebuilds each second, then minute
keying once it has a time) and the skewed-server pause stamp. ID
formatting uses Locale.ROOT. Parity: Tests table row for
TranscriptStreamWorkTests.swift, row sentence notes the difference.

Verified on the Android VM: the new tests pass; dev's per-second key,
the previous commit's untimed-only rule and an unconditional minute key
each fail at least one of them. Full scripts/check.sh.
@Tarquinen Tarquinen changed the title Rebuild transcript time stamps once a minute while streaming perf(session): rebuild transcript time stamps once a minute while streaming Nov 21, 2026
@Tarquinen
Tarquinen merged commit 90abdac into dev Nov 21, 2026
2 checks passed
@Tarquinen
Tarquinen deleted the timestamps-per-minute branch November 21, 2026 00:48
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