perf(serve): SSE live pump reads incrementally #137

Merged
xiaomo merged 1 commits from fix/130-sse-incremental into main 2026-05-08 15:00:45 +00:00
Owner

What

SSE live pump now reads only new bytes instead of the entire JSONL file.

Why

Issue #130 — long-running threads produce large JSONL files. Reading the whole file on every fs watch event is wasteful.

Changes

  • routes-live.ts — replaced readFile + slice with Bun.file().slice(offset, size) via readNewBytes() helper. Handles truncation, early returns when no new data.

Ref

Closes #130. 262 tests pass.

## What SSE live pump now reads only new bytes instead of the entire JSONL file. ## Why Issue #130 — long-running threads produce large JSONL files. Reading the whole file on every fs watch event is wasteful. ## Changes - **routes-live.ts** — replaced `readFile` + slice with `Bun.file().slice(offset, size)` via `readNewBytes()` helper. Handles truncation, early returns when no new data. ## Ref Closes #130. 262 tests pass.
xingyue added 1 commit 2026-05-08 10:14:23 +00:00
Use Bun.file().slice() to read only new bytes from the last known
offset instead of re-reading the entire JSONL file on every fs watch.

- readNewBytes() helper with byte-offset tracking
- Handles file truncation (resets offset)
- Early return when no new data

Closes #130
xiaomo approved these changes 2026-05-08 15:00:30 +00:00
xiaomo left a comment
Owner

PR #137: SSE 增量读取

readFile 全文读 → Bun.file().slice(offset, size) 增量读。statSync 检测 truncation 正确处理。parseNewLines 简化为纯 chunk 拼接。性能优化到位。LGTM。

## PR #137: SSE 增量读取 ✅ `readFile` 全文读 → `Bun.file().slice(offset, size)` 增量读。`statSync` 检测 truncation 正确处理。`parseNewLines` 简化为纯 chunk 拼接。性能优化到位。LGTM。
xiaomo merged commit 2c0e744ebf into main 2026-05-08 15:00:45 +00:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/workflow#137