Skip to content

[PR] perf: index covered timestamps in compression receipts - #6716

Merged
ranxianglei merged 2 commits into
ranxianglei:masterfrom
Afloat16:2026-11-14_linear-coverage-timestamps
Nov 15, 2026
Merged

ranxianglei merged 2 commits into
ranxianglei:masterfrom
Afloat16:2026-11-14_linear-coverage-timestamps

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Closes #6715.

Problem

Each successful compression receipt resolves the covered time window from persisted first-sight timestamps. blockCoverageTimes() deduplicates each effective message ID with a scan of all IDs already collected, before including the boundary refs. A long fold therefore performs quadratic membership work just to format its timestamp span. Message timestamps are enabled by default, so this runs in the normal compression path.

Change

Index covered IDs and their first-read timestamps in an insertion-ordered Map. Effective IDs and resolved start/end refs retain the same order, each stamp is read once, and a missing stamp still suppresses the entire range. The change is four replacements in the receipt helper; it adds no setting, dependency, wire field, or kernel change.

Verification

  • Six added semantic controls cover duplicate IDs and boundary aliases, first-read order, resolved boundaries outside effective coverage, missing boundary stamps, empty coverage, unresolved block-shaped refs, zero/negative timestamps, object-like ID names, and non-mutation. They preserve the existing behavior rather than changing receipt bytes.
  • 46/46 related tests pass on the rebased head: fingerprint, timestamp display toggles/defaults, compression refolds, and kernel timestamp coverage.
  • scripts/bench-coverage-timestamps.ts exercises the actual public applyRanges() path with valid typed text messages, a real kernel, deterministic stored timestamps, UTC display, and persistence disabled. Fixture construction, hashing, and assertions are outside the timed region. Each process first warms up with two 100-message calls.
  • On Node 24.22.1/Linux, three sequential alternating base/fix pairs compress 19,990 of 20,000 messages. Median elapsed time is 8,803.1 ms → 7,804.7 ms, and median process CPU is 9,068.0 ms → 8,067.3 ms. Base samples range from 8,558.1–9,118.7 ms; fixed samples range from 7,754.1–7,804.8 ms. All six complete returned results have the same SHA-256: 53cde3b8608d64a7792bc01c9033e58ea9b95c44dee16667d63cc5ca385c1921.
  • These measurements describe this synthetic end-to-end workload. Other compression steps still dominate much of its cost; this PR does not make the entire compression pipeline linear.
  • Full npm run typecheck, standalone strict TypeScript checking of the benchmark, npm run build, and git diff --check pass. Full-suite status comes from hosted CI on the pushed head.

Reproduce one measured sample at each revision with:

node --import ./tests/preload-test-env.mjs --import ./tests/preload-storage-baseline.mjs --import tsx scripts/bench-coverage-timestamps.ts 20000 1

The formal comparison uses current base 3858b6956abab52da781c2436c0245586ce18358, which already contains the separate image-note lookup optimization from #6612. Earlier exploratory timings on an older base are not used here.

History check

Checked the complete Afloat16 production-patch index and all-state searches for the helper and timestamp/coverage performance. #5236 introduces the existing receipt helper and its repeated scan. #6612 indexes a different image-note lookup inside applyRanges(); #6597 changes JSON-response evidence serialization. Neither modifies timestamp coverage collection. The actual updated master still has the original helper. Related timestamp/release summaries and storage-reactivation work do not duplicate this change.

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

查重: 不重复。 Searched open + closed issues/PRs by failure signature (helper name + timestamp/coverage perf), not just title: #5236 introduced the original blockCoverageTimes helper with the repeated scan (origin, not a duplicate); #6612 (already in this base) indexes a different image-note lookup inside applyRanges(); #6705 rewrites fold coverage in src/fold-reconcile.ts — different file, different mechanism; #6597 changes JSON-response evidence serialization. No other open or closed PR touches blockCoverageTimes.

标签: bug, scope/kernel, p2 — 性能缺陷落在默认开启的正常压缩路径上(长 fold 的 O(N²) 成员扫描);范围是宿主侧压缩回执引擎(未动 kernel/);p2 因为只是性能退化,不涉及可用性或缓存泄露。

Review — direction (①): Verified against the PR base, which is exactly current master (3858b695), so the branch is fresh. blockCoverageTimes() (src/stream.ts:523) dedups every covered id with covered.some((e) => e.id === id) — a linear scan of everything collected so far, so a fold covering N messages pays O(N²) membership work on every successful compress. The span gate resolveMessageTimestamps (src/config.ts:2944) defaults to TRUE, so this runs on the normal path, as the issue states. The fix — an insertion-ordered Map<id, firstReadStamp> — removes the quadratic scan at its source (root cause, not a mask) while preserving first-read order, one stamp read per id, and missing-stamp suppression.

What I verified myself on the PR head (not just the PR's claims):

  • Targeted suites on the head: tests/issue4313-fingerprint.test.ts (10 tests incl. the 6 new), tests/issue4313-message-timestamp-toggle.test.ts, tests/message-timestamps-default-on.test.ts, tests/compress-fingerprint-refold.test.ts, tests/resume-miss-timestamp-seed.test.ts, tests/issue404-restore-timestamps.test.ts, tests/attach-invalid-timestamps.test.ts — 52/52 pass; kernel suite 1636/1636 pass.
  • npm run typecheck clean; standalone strict tsc on the new benchmark script clean.
  • Ran the shipped benchmark myself (Node 22.23.2, 20,000 messages, 1 sample per side):
    • base 3858b695: 6,006.1 ms elapsed / 6,193.7 ms CPU
    • PR head: 5,421.3 ms elapsed / 5,614.8 ms CPU
    • both sides produce SHA-256 53cde3b8…c1921 — the same digest the PR reports for all six of its samples, i.e. receipts are byte-identical to base and to the author's measurement. The ~10% end-to-end gain here matches the author's ~11% on Node 24.
  • CI on head 185042eb54: 17 success / 13 skipped / 0 failure — full test shards and all guard lanes green.

Regression pass (②): the receipt fingerprint line is a pure function of (blockId, summary, range); the range values are unchanged (same min/max, same null conditions, same first-read order — pinned by the Proxy read-order test), so receipt bytes, the log path (summaryFingerprintLogLine), and the external-summary-surface.ts consumer are all unaffected. Both compression modes share the same pure helper — no mode-specific behavior. No config, env, wire, persistence, or kernel surface touched.

Quality (④/⑤/⑤b): the six new tests are real semantic controls (exact {startTs,endTs} assertions, read-order pin via Proxy, non-mutation pin), not tautologies, and they live in the file where the existing blockCoverageTimes tests already are. The benchmark follows the established scripts/bench-*.ts pattern (cf. bench-fold-image-notes.ts from #6612) with warmup, median, and a byte-stability assertion. Diff is 3 files / +128 −4, every line on-topic; no dead code, no new dependencies, style consistent. Meets the external-submission bar — no rework needed.

One finding — pre-existing stale comment at the call site (fix prepared, push blocked):
src/stream.ts:1646-1649 still says:

// #4313 toggle (PR #5236): the [start – end] coverage span rides the
// same flag as the wire tags — default OFF keeps receipts byte-identical
// to pre-feature master. Storage still stamps unconditionally; this only
// gates the display span.

but the #4313 default-on follow-up (2026-10-31) flipped resolveMessageTimestamps to default TRUE — the PR's own premise ("Message timestamps are enabled by default") confirms it. Correct wording:

// #4313 toggle (PR #5236; default-on follow-up): the [start – end]
// coverage span rides the same flag as the wire tags — default ON; the
// opt-out (file `compress.messageTimestamps: false` or env "0") keeps
// receipts byte-identical to pre-feature master. Storage still stamps
// unconditionally; this only gates the display span.

I have this ready as a standalone docs: commit, but the PR has "Allow edits by maintainers" disabled, so I can't push to your branch. Could you either enable maintainer edits (I'll push the prepared commit) or apply the wording fix yourself? It is pre-existing (on master since 2026-10-31), not introduced by this PR — it does not block the merge.

Verdict: mergeable. Minimal, behavior-preserving, independently verified (identical receipt bytes + measured ~10% gain), full CI green, tests are real.

结构化八问:

  1. 是什么问题:压缩回执的时间戳区间助手用数组扫描去重已覆盖消息 ID,每次成功的长 fold 都要付 O(N²) 的成员扫描代价才能格式化 [start – end] 区间。
  2. 什么原因导致的:blockCoverageTimes()([PR] feat(#4313): 每条消息和每个压缩块带上不可变本地时间戳——模型从此分清什么早发生、什么刚发生(默认关闭) #5236 引入)对每个待考虑 ID 做 covered.some(e => e.id === id) 线性扫描;时间戳默认开启,所以落在正常压缩路径上。
  3. 影响范围与严重程度:所有开启消息时间戳(默认开)的成功 fold,代价随覆盖消息数平方增长(本机 19,990 条 fold 实测多付约 0.6 s)。仅性能退化,回执正确性与可用性不受影响。p2。
  4. 怎么修复的:用插入序 Map<id, 首次读到的戳> 替换数组+扫描——O(1) 去重、保持首读顺序、每个戳只读一次、缺戳仍整段抑制。helper 内四处替换,外加可复现的公共路径基准脚本和六个语义控制测试。
  5. 是否有回归问题:无。已逐项清点触碰路径的既有行为:回执字节(base 与 PR 的 SHA-256 一致,且与作者六份样本一致)、缺戳抑制、边界 ref 解析、空覆盖返回 null、戳读取顺序、不可变性、日志路径、双压缩模式——全部保持并有测试钉住。
  6. 是否破坏缓存:否。回执字节不变,前缀缓存行为不受影响;不涉及任何缓存/重试/游标/去重键策略。
  7. 是否改了设计方向:否。同一 helper、同一契约、同一调用点,仅内部数据结构变化。
  8. 是否引入了新的配置:否。无新 env、配置键、CLI 标志、依赖、wire 字段或 kernel 变更。

判定:可合(mergeable)——上述过时注释为既有问题、已给出修法,由作者处理,不阻塞合并。

@ranxianglei ranxianglei added bug Something isn't working p2 scope/kernel labels Nov 14, 2026
@Afloat16

Copy link
Copy Markdown
Contributor Author

已在 dd6d34a 按你给出的措辞修正调用点注释:时间戳默认开启,显式 opt-out 才保持旧回执显示方式。这个跟进只改注释,未改运行逻辑。

更新后的 head 已完成 CI:37 项成功、13 项跳过,无失败或待运行项。感谢对回执字节一致性和端到端性能的独立验证;目前没有其余待处理的审阅修改。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

已逐项核实 dd6d34a,并发现一个时间线事实需要说明:

1. 跟进 commit 验证(diff 185042e..dd6d34a):恰好 1 个文件、5 增 4 删,全部是 src/stream.ts:1646-1650 的注释替换,措辞与 review 中给出的建议一致(default ON;opt-out 经 compress.messageTimestamps: false 或 env "0" 才保持旧回执显示)。无任何运行逻辑变化。✓

2. 时间线事实(重要):性能主修复已经先于你的跟进 commit 合入 master——batch7-wave7 于 2026-11-14 20:53 (+0800) 以 merge commit b07fffaf03 将本 PR 的 185042eb54 合入 master,而 dd6d34a 推送于 21:41。因此:

  • 性能修复(Map 化 + 基准脚本 + 六个测试)已在 master 上生效;
  • 本 PR 相对当前 master 的 diff 现在恰好只剩这个注释修正(5 行);
  • master 上 src/stream.ts:1647 的过时注释("default OFF keeps receipts")目前仍在,正由本 PR 的 head 修复。

3. 当前 head 的 CI 与合并状态(实测,非转述):

  • 镜像缓存(2026-11-14 16:03Z 抓取 dd6d34a):30 项 check,17 success / 13 skipped / 0 failed / 0 pending——与你报告的「无失败或待运行项」一致(成功计数口径不同:GitHub UI 按 check-run 计 37,镜像按 job 计 17)。
  • git merge-tree 模拟 head 并入当前 master:零冲突;head 已包含合入的 185042eb54,合并恰好只追加这一个注释 commit。分支虽落后 master 71 个 commit,但唯一重叠的 stream.ts 改动就是本 PR 自己已合入的那部分,不构成阻塞。

4. 处置:按「一个线程一个修复 PR」规则,不开新 PR——现有 PR 的 head 已携带全部剩余修改,无需任何新分支。

结构化八问:

  1. 是什么问题:本轮对象是跟进的注释修正;原性能问题(回执时间戳去重的 O(N²) 扫描)已修复并合入 master。
  2. 什么原因导致的:注释过时源于 feat: Support precise timestamps for each message, allowing the model to recognize which messages are outdated and which | feat: 给每个消息支持精确时间,以让模型认识到什么消息是过期的什么是当前的新的 #4313 默认值翻转(2026-10-31 起默认 ON)后调用点注释未同步;状态错位源于批量合并取的是修复前的 head(20:53 合并 < 21:41 推送)。
  3. 影响范围与严重程度:注释修正零运行影响;master 上过时的注释本身只是文档准确性问题(误导读者以为默认关闭),p3 级。
  4. 怎么修复的:作者按 review 建议措辞在 dd6d34a 修正注释;已验证 diff 相对上一 review head 仅此一处。
  5. 是否有回归问题:无。注释-only 变更,零代码 diff;性能部分此前已完整验证且已合入。
  6. 是否破坏缓存:否。
  7. 是否改了设计方向:否。
  8. 是否引入了新的配置:否。

判定:可合——当前 head(dd6d34af)相对最新 master 的 diff 即注释修正本身,CI 全绿、模拟合并零冲突。等待 owner 合并(合并权在 human)。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working p2 scope/kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compression receipt timestamps repeatedly scan all covered IDs

2 participants