perf(runtime-host): reduce repeated encoding across 16 page builders - #5166
perf(runtime-host): reduce repeated encoding across 16 page builders#5166chinawch007 wants to merge 3 commits into
Conversation
性能测试报告英文版本Issue #5038: Pagination Assembly Performance ReportOutcome and scopeThis report measures all 16 real pagination entry points, including variations in Connection catalog size, item length, and page position. Both Usage LLM and tool logs reference real Sessions and read their titles from the actual Session store. Shared-session and multiple-session workloads verify title reads and returned text for each request workload. The primary experiment contains 58 datasets and 102 request workloads, plus 93 page/protocol replay and supplementary Memory storage workloads. In total: 195 workloads and 39,000 timed samples. This documentation revision makes two workload boundaries explicit: The production change remains the five original examples plus 11 additional pagination functions: 13 business source files and one shared budget helper. Complete pagination results match between versions for every primary dataset and are checked against expected items or identities. Each request workload is checked for equivalent production/decoded results and identical transmitted byte counts before timed sampling. Repeated encoding decreases for multi-item pages, while unchanged reads, scans, parsing, and projections remain in real-query timings. Whole-query speedups can therefore be smaller than page/protocol speedups; small or final pages may not improve. All results are retained without latency-based filtering. Versions, environment, and sampling
Primary experiment: real paths and workload boundariesAll primary workloads use valid inputs through
In dataset names, The three Runtime Resource datasets seed only persisted terminal ShellRun records (1 / 8 / 70), without launching processes. Session events, run history, and transcript messages are empty: The downstream consumer for every path is the production protocol decoder. Other workload boundaries: Plugin measures the entries view; other views share its builder. External Session uses the real Claude Code file adapter and SQLite batch lookup with no prior imports. Usage logs measures both LLM and tool entry points. Invocable Skills uses a new-session context, real workspace resolution, and a fixed Read-tool capability. These choices restrict workloads without substituting data reads or pagination algorithms. SQLite counts are rows returned by StatementSync Representative real-query resultsFor each path, select the first page of its largest normal dataset. The main Usage logs row uses LLM with 130 logs across 16 Sessions; other workloads appear in the dedicated and full tables. Plugin's additional large-item boundary case is also retained in the full table. All arrows mean before → after; encoding volumes are cumulative UTF-8 bytes and timings are milliseconds.
In this primary run, 10 of 102 workloads have a higher after median than before. All remain in the full table. One local experiment cannot establish small differences as stable regressions, nor guarantee speedups for every workload. Reduced repeated page encoding and changes in whole-query latency are evaluated separately. Usage logs: real Session title readsEach of LLM and tool has five datasets: 1 log / 1 Session, 8 / 1, 8 / 8, 130 / 1, and 130 / 16. Logs reference Sessions round-robin in creation order and are queried newest-first. Titles contain CJK characters, emoji, quotes, and backslashes. They stay within the 80-code-point Session name limit and below the Usage projection cap; returned titles are independently checked against the seeded text. The coordinator uses the same Usage buckets reads groups and merges canonical runtime usage without Session title lookup, matching production. Tool logs reads its telemetry ledger and Session titles without the LLM canonical merge. These paths are described separately. Earlier untitled Usage log results are archived and are not mixed into this run. Since this workload adds Session references and titles, differences between the old and new benchmark runs cannot be attributed to a code change. Usage buckets and LLM logs seed records only in telemetry; the canonical model-call ledger is not populated, so
Connection catalog coverageConnection count, enabled models per connection, and UTF-8/escaped model-identifier length vary across datasets. Each dataset starts with a real start request and follows returned cursor/revision values to completion. Multi-page datasets measure first, available middle, and final pages instead of constructing offsets manually.
Correctness and acceptance conclusions
Reproduction and artifactsArtifacts are in the Git-ignored directory
With dependencies installed and fixtures retained, run from a clean working tree at the optimized commit. These commands overwrite experiment results: python3 perf-results/page-assembly-5038/prepare-run.py
node perf-results/page-assembly-5038/authority-cases.mjs > perf-results/page-assembly-5038/authority-benchmark.log 2>&1
MAKA_PAGE_CAPTURE=0 MAKA_PAGE_STORAGE=1 node --import ./perf-results/page-assembly-5038/capture.mjs ./perf-results/page-assembly-5038/measure.mjs > perf-results/page-assembly-5038/benchmark.log 2>&1
node perf-results/page-assembly-5038/check-serialization.mjs
python3 perf-results/page-assembly-5038/finalize-report.pyTemporary real storage requires owner-lock access. Run the two formal benchmarks sequentially to avoid contention. Retained regression logs correspond to the current commit. To repeat behavioral checks, use Appendix A: all real-query workloads
Appendix B: serialization, parsing, and SQLite rows returned
Appendix C: all supplementary workloadsThese 93 workloads retain the earlier scope: 15 page builders start from captured or synthetic projections, followed by protocol validation, the outbound queue, and consumer decoding. Directory includes the filesystem authority; eight Memory authority cases additionally include real storage and Markdown parsing. Larger speedups here do not substitute for real-query results in Appendix A. Single-item encoding can increase by four bytes.
中文版本# Issue #5038:分页组装优化性能测试报告结论与交付范围本报告测量全部 16 个真实分页入口,并覆盖 Connection catalog 的规模、条目大小及页位置变化。Usage 的 LLM/tool 日志均关联真实 Session,通过实际 Session store 读取标题,覆盖共享和多个 Session,并核验每个请求负载的标题读取与返回文本。主实验包含 58 组数据集、102 个请求负载,另有 93 组组页/协议重放及 Memory 存储负载。合计 195 组负载、39,000 个正式耗时样本。 本次说明修订明确两项负载边界:Usage buckets/LLM logs 的 生产代码范围保持为原 issue 的 5 个示例及后续确认的 11 个分页函数,共 13 个业务源码文件和一个公共预算工具。 所有主实验数据集的完整翻页结果前后一致,并核对了预期条目或身份集合;每个请求负载均在正式采样前核对生产结果、消费者解码结果及传输字节数。多条目页面的重复编码减少成立,但真实查询中未改动的读取、扫描、解析和投影仍占时间,因此整体查询提速通常小于组页子链提速;小页及末页可能不提速。下文保留所有结果,不使用耗时阈值筛选样本。 版本、环境与采样
主实验:实际数据链与负载边界所有主实验使用合法输入经
数据集名称中的 Runtime Resource 的三个数据集只播种持久化的已结束 ShellRun 记录(1/8/70 条),不启动子进程;Session 的事件、运行历史及 transcript 消息均为空,即 所有路径的下游消费者均为生产协议解码器。其他范围限制:Plugin 测量 entries 视图,其他视图共用组页函数;External Session 测量真实 Claude Code 文件适配器及零导入记录的 SQLite 批量查找;Usage logs 同时测量 LLM/tool 两个入口;Skill invocable 使用新 Session 上下文、实际目录解析及固定 Read 工具能力。它们限定负载,不替换数据读取或组页算法。 SQLite 指标为 StatementSync 真实查询的代表性结果每个入口选择最大普通数据集的首页;Usage logs 主表取 130 条日志、16 个 Session 的 LLM 分支,其他结果见专项与全量表;Plugin 的超大单条目边界场景另列于全量表。箭头均为 before → after,编码量为累计 UTF-8 字节,耗时为 ms。
本次主实验有 10 / 102 个请求负载的 after median 高于 before。它们均保留在全量表;单次本机实验不能将小幅差异解释为稳定回归,也不能保证每个负载都会提速。组页重复编码的减少与整次查询耗时的变化分别评价。 Usage 日志:真实 Session 标题读取LLM/tool 各包含五组数据:1 条日志/1 个 Session,8 条/1 个,8 条/8 个,130 条/1 个,130 条/16 个。日志按创建次序轮流关联 Session,查询按时间倒序。标题使用中文、emoji、引号和反斜杠,长度在 Session 的 80 个码点限制内,并低于 Usage 投影上限;使用播种的原文独立核对返回标题。 协调器接入与实际应用相同的 Usage buckets 按生产流程只读取分组并合并 canonical runtime usage,不读取 Session 标题。Tool 日志读取自己的 telemetry ledger 和 Session 标题,不执行 LLM canonical merge。报告已分别描述这些路径。旧的无标题 Usage 日志数据保存在历史目录,未混入本轮结果;由于负载增加了 Session 关联和标题,不能把新旧两轮耗时差当作代码变化的效果。 Usage buckets 和 LLM logs 的记录仅写入 telemetry,canonical 模型调用账本未播种记录,即所有相关数据集的
Connection catalog 专项连接数、每个连接启用的模型数、模型标识中的 UTF-8/转义长度分别变化。每个数据集从 start 请求沿真实返回 cursor/revision 完整读取;有多页时测首页、可用的中间页和末页,而不是手工构造 offset。
正确性与验收结论
复现与文件实验文件位于 Git 忽略目录
在优化后提交的干净工作区安装依赖并保留 fixtures 后,从仓库根目录执行;这些命令覆盖实验结果: python3 perf-results/page-assembly-5038/prepare-run.py
node perf-results/page-assembly-5038/authority-cases.mjs > perf-results/page-assembly-5038/authority-benchmark.log 2>&1
MAKA_PAGE_CAPTURE=0 MAKA_PAGE_STORAGE=1 node --import ./perf-results/page-assembly-5038/capture.mjs ./perf-results/page-assembly-5038/measure.mjs > perf-results/page-assembly-5038/benchmark.log 2>&1
node perf-results/page-assembly-5038/check-serialization.mjs
python3 perf-results/page-assembly-5038/finalize-report.py临时真实存储需要 owner-lock 权限。两组正式性能命令应顺序执行,避免彼此争用。保留的回归日志对应当前提交;如需重跑行为测试,可执行 附录 A:全部真实查询负载
附录 B:真实查询编码、解析与 SQLite 返回行数
附录 C:全部补充负载这 93 组保留旧方案的测量范围:15 个组页函数从已捕获或合成投影开始,经协议验证、发送队列和消费者解码;目录包含实际 filesystem authority;Memory authority 的 8 组另含真实存储和 Markdown 解析。这里的较大提速不能替代附录 A 的真实查询结果。单条记录累计编码可能增加 4 字节。
|
|
这是个简短人看版,16处代码优化代表性场景性能前后对此。单独测被优化函数的前后性能差距很明显,但这里实际展示出来的有的优化效果不明显。原因很好理解,如果某个查询原来大量时间都花在重复组页编码上,改善就大;如果多数时间花在读文件、扫描和解析上,组页即使省下很多工作,整次查询改善也有限。 每项取最大普通数据集的首页,耗时为热查询中位数(median),按耗时减少比例降序排列。
注:这是代表性场景对比,不是各入口所有负载的平均提升。完整 102 个请求负载中,92 个 median 改善,10 个未改善。 |
Replace repeated candidate-page copies and full-page serialization with a shared incremental UTF-8 JSON budget across 16 pagination builders. Preserve projection, cursor reservation, limits and protocol validation. Cover exact byte boundaries, escaped Unicode and complete pagination in shared budget tests and existing coordinator and protocol test suites. Refs apache#5038 Generated-by: OpenAI Codex
81bed5f to
d405de3
Compare
Account for the two pagination coverage cases; require 93 passing tests and zero skips. Refs apache#5038 Generated-by: OpenAI Codex
Expect 93 passing Skill catalog tests in the workflow policy checks, matching the Windows gate after pagination coverage was added. Refs apache#5038 Generated-by: OpenAI Codex
Summary
The Storage/Runtime Host read-path audit found 11 additional page builders with the same repeated-encoding pattern as the five examples in #5038. This PR optimizes all 16 builders in
packages/runtime-host: each previously copied the accepted-item array and serialized the entire candidate page after every append, only to discard that encoding after checking its size.Refs #5038 — first delivery item: encoding and page assembly.
A shared
JsonArrayPageBudgetmeasures the fixed page envelope once, encodes each candidate item's UTF-8 JSON once during budgeting, and adds separators and the actual candidate cursor/nextOffset. Items are appended in place only when the candidate fits. This removes the repeated array copies and whole-page size checks, so already accepted items are no longer re-encoded for each subsequent candidate.Existing projections, item/byte limits, cursor reservation, revisions, and error behavior are preserved. Result-object budgets remain distinct from message-frame budgets; final messages continue through the existing protocol validation and encoding path. There is no intended externally observable behavior change.
Verification
git diff --checkpassed. Validation is scoped to the affected code and suites; full-repository CI parity is not claimed here.30cf0beb0def57626df3fdbf8c7ab4d0d3436896with81bed5f8100512b00977a08d5a313c3c29f29c45under identical workloads. The primary experiment covers all 16 real query paths, 58 datasets, and 102 request workloads, from actual data reads through protocol validation, outbound encoding, in-memory transport, and consumer decoding. Another 93 workloads isolate page/protocol costs. Each version receives 30 warm-ups and 100 timed samples per workload, totaling 39,000 samples.These are local synthetic warm-query measurements. Usage buckets/LLM logs have an empty canonical ledger; Runtime Resource has empty transcript history. The report does not measure retained memory/RSS, cold-process latency, socket/UI timing, or SQL scan/WAL costs, and makes no improvement claims for those metrics.
Benchmark package:
5038-pagination-benchmark-81bed5f-v1.zipcontains English/Chinese reports, scripts, fixtures, raw samples, and a standalone verifier.5038-pagination-benchmark-81bed5f-v1.zip
AI use
Select exactly one:
Tool(s) and scope: OpenAI Codex assisted with code-path analysis, implementation, tests, benchmarks, and documentation. The implementation commit includes
Generated-by: OpenAI Codex; retain this trailer in the squash commit.Checklist
The first item includes the benchmark's serialization-work assertions; behavioral checks intentionally preserve and pass against the baseline semantics. Local check coverage is described under Verification.
Does this PR entail a change in behavior?