Files
deepseek-harness/scripts
imccyuandimccyu e255853b03 perf(client-ui-stats): fold and publish wide PTC runs linearly (#9420)
* perf(client-ui-stats): add a PTC fold and publication diagnostic

One root run_code call dispatching 1,000 to 10,000 settled subcalls reports
the Statistics fold, the first and repeated Code-Mode publication, and the
live assembler window. Threshold-free, outside every CI lane.

* perf(client-ui-stats): fold tool calls into Context-private indexes

Every event copied the growing call and dispatch-start records, so one
Code-Mode root call with n nested dispatches cost O(n^2). The four
fold collections are Maps the Context mutates in place now, and update()
returns the same State.

The call list stops sorting the whole index: a Context receives its
matches in ascending seq, so insertion order is the order the table
lists.

* perf(client-ui-stats): publish only the bounded Code-Mode prefix

The Code-Mode node rebuilt every step metric, including a sort of every
dispatch, for each settle, though it publishes at most 12 rows. It now
materializes that prefix from the index, republishes the node it already
published while the prefix is unchanged, and coalesces publications to
one per frame. Targeted snapshot updates skip the rebuild when every
upserted node is the published one.

* docs(client-ui-stats): record the linear Statistics fold

Agent Note for the in-place call index, the bounded Code-Mode prefix, the
retention bound, and the publication cadence, with the measured before and
after table.

* fix(client-ui-stats): reuse the node the Assembler already holds

The Code-Mode Definition kept its own module-level WeakMap of published
nodes, keyed by State. The Assembler already stores each Context's last
published node in `context.current`, which is where the Chat Definition
reads it, so the extra cache hid state ownership for nothing.

It also missed in two reachable cases: a failed dispatch returns a fresh
State, and `callList` rebuilds every row past the step text budget as a
truncated copy, so an unchanged prefix arrived as fresh objects and the
reference comparison failed. The snapshot rebuild the cache was meant to
skip then ran anyway.

Read `context.current` instead and compare rows field by field. Edited
the publication comment to state the real cadence: the Assembler
materializes an `animation-frame` publication after three frames.

* docs(notes): correct the Statistics fold note against the code

Three statements did not match what shipped. The scalar counters the
retention bound leaves alone are `toolPairs`, `toolMs`, `toolOpen`, and
`toolMissing`, not `pairs`/`ms`/`open`/`missing`, and they are written by
the native `tool/call` and `tool/result` branches rather than by the
dispatch branch; only `tools` and `toolErrors` count every dispatch. The
retained records are the first `CALL_LIMIT` displayable dispatches, not
the first `CALL_LIMIT` dispatches, so a nested runner no longer takes a
slot. The publication cadence is three animation frames, not one.

* test(scripts): expect the Statistics diagnostic in the perf inventory

The manual `test:web:perf` inventory is pinned item by item, and the new
`client-ui-stats` entry left the expectation behind, so the required
coverage partition failed on it.

---------

Co-authored-by: imccyu <cc.yu@deepseek.com>
2026-11-27 19:28:33 +08:00
..
2026-09-08 22:31:16 +08:00