Cut daemon and main PTY batch windows 8ms -> 2ms

At 9% pipeline utilization the DSR-under-load latency is fixed batching
windows, not queue depth (proved by the MessageChannel drain lever
moving nothing). Both hops charged an expected half-window per chunk;
2ms keeps burst coalescing at negligible IPC overhead (~500 msgs/s
worst case vs MB/s payloads).

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
Jinwoo-H
2026-07-03 16:28:36 -04:00
co-authored by Orca
parent 2434dfaaee
commit e67a91d7af
3 changed files with 127 additions and 4 deletions
@@ -11,9 +11,12 @@ type PendingStreamDataBatch = {
queuedChars: number
}
// Why: match main-process PTY IPC batching to avoid adding latency while
// removing daemon socket writes and JSON framing during bursty output.
const STREAM_DATA_BATCH_INTERVAL_MS = 8
// Why 2ms: under continuous agent output every chunk waits an expected
// half-window here AND again in main's PTY batch — at 8ms each that was
// ~8ms of the measured ~19ms DSR-under-load latency. 2ms keeps burst
// coalescing (~500 socket writes/s worst case, ~100B framing overhead per
// write against MB/s payloads) while cutting the fixed latency tax 4x.
const STREAM_DATA_BATCH_INTERVAL_MS = 2
type EnqueueOptions = {
flushImmediately?: boolean
+5 -1
View File
@@ -1445,7 +1445,11 @@ export function registerPtyHandlers(
let flushTimer: ReturnType<typeof setTimeout> | null = null
let rendererInFlightTotalChars = 0
let pendingDroppedChars = 0
const PTY_BATCH_INTERVAL_MS = 8
// Why 2ms: pairs with the daemon stream batcher (see
// daemon-stream-data-batcher.ts) — both hops charged an expected
// half-window per chunk; 2ms keeps flood coalescing at negligible IPC
// overhead while cutting the pipeline's fixed latency tax.
const PTY_BATCH_INTERVAL_MS = 2
const PTY_BATCH_DRAIN_CONTINUE_MS = 1
const PTY_BATCH_FLUSH_CHUNK_CHARS = 16 * 1024
const PTY_BATCH_FLUSH_MAX_WRITES = 2
@@ -0,0 +1,116 @@
{
"benchmark": "terminal-pipeline",
"label": "dev-msgchannel",
"timestamp": "2026-07-03T20:25:28.128Z",
"terminal": {
"program": "Orca",
"version": "1.4.120",
"term": "xterm-256color",
"cols": 282,
"rows": 80,
"tty": true
},
"machine": {
"platform": "darwin",
"arch": "arm64",
"cpu": "Apple M4",
"release": "25.2.0",
"node": "v26.0.0"
},
"config": {
"sizeMb": 3,
"iterations": 5,
"dsrCount": 200
},
"dsrIdle": {
"count": 200,
"p50": 1.0432919999999797,
"p90": 2.4471249999999145,
"p99": 45.014125000000035,
"max": 57.02449999999999,
"timeouts": 0
},
"throughput": [
{
"fixture": "ascii-log",
"fixtureBytes": 3145851,
"wallMs": {
"count": 5,
"p50": 425.00216699999964,
"p90": 472.5160420000002,
"p99": 472.5160420000002,
"max": 472.5160420000002
},
"mbPerSec": {
"count": 5,
"p50": 7.059063541059357,
"p90": 7.810209697729803,
"p99": 7.810209697729803,
"max": 7.810209697729803
}
},
{
"fixture": "cjk-emoji",
"fixtureBytes": 3145785,
"wallMs": {
"count": 5,
"p50": 331.4376660000007,
"p90": 383.04050000000007,
"p99": 383.04050000000007,
"max": 383.04050000000007
},
"mbPerSec": {
"count": 5,
"p50": 9.051639771793555,
"p90": 9.61670443426201,
"p99": 9.61670443426201,
"max": 9.61670443426201
}
},
{
"fixture": "agent-tui",
"fixtureBytes": 3146560,
"wallMs": {
"count": 5,
"p50": 328.68583300000046,
"p90": 357.50683300000037,
"p99": 357.50683300000037,
"max": 357.50683300000037
},
"mbPerSec": {
"count": 5,
"p50": 9.129670815569485,
"p90": 9.548479391576642,
"p99": 9.548479391576642,
"max": 9.548479391576642
}
},
{
"fixture": "styles-stress",
"fixtureBytes": 3145734,
"wallMs": {
"count": 5,
"p50": 753.0036249999994,
"p90": 770.5100000000002,
"p99": 770.5100000000002,
"max": 770.5100000000002
},
"mbPerSec": {
"count": 5,
"p50": 3.9840521644844684,
"p90": 4.840472273920311,
"p99": 4.840472273920311,
"max": 4.840472273920311
}
}
],
"dsrUnderLoad": {
"paceBytesPerSec": 1048576,
"count": 50,
"p50": 19.011790999998993,
"p90": 22.73199999999997,
"p99": 28.13012499999968,
"max": 28.13012499999968,
"timeouts": 0
}
}