dsh-coldread-cache: DSH Long Session Parsing Optimization Plugin

DeepSeek Harness (DSH) Plugin: Keeping a resident parsed event log for sessions to allow local incremental parsing expansion rather than invalidating it—parsing long sessions once per host process, rather than once per read.

Preface

The session-persistence-jsonl backend in DSH has a two-entry cache limit keyed by a revision derived from stat. Every append changes the revision, causing cache misses for the active session almost on every read. A miss implies a full cold read: reading the entire file, decoding frame by frame, and parsing line by line. For long sessions, as the number of turns increases, this overhead directly causes UI stuttering.

This plugin aims to solve this problem. It does not modify any files in the DSH installation directory; it only writes its own properties onto the running persistence backend instance.

Core Features

  1. Resident Session Parse Log: Maintains a resident decoder for each session.
  2. Expand Resident Parse on Append, Don’t Rebuild: Returns directly if the file hasn’t changed; if the file has grown, it reads only the new bytes and feeds them to the resident decoder to append.
  3. Parse Long Sessions Once Per Process: The same file is parsed only once during the process lifecycle.
  4. Handle freezeStoredEvents: Before returning results, the backend calls freezeStoredEvents to freeze the event array. The plugin must keep the resident decoder unfrozen and issue a frozen copy for every read to avoid the “object is not extensible” error.
  5. Correctness Guarantees: The resident result is reused only when equivalence can be proven. The extension path is taken only when conditions such as the same file path, growth-only changes, complete tail frames, and format constraints are met.

Installation and Activation

The plugin is loaded by the profile. It is recommended to install it using the DSH built-in plugin command:

dsh plugin --profile <name> add dsh-coldread-cache

Manual mounting requires modifying three places simultaneously:
* <profile>/package.json: Add this package to dependencies and dsh.profile.bundles.
* <profile>/cordis.patch.yml: Add insertion lines.

Configuration

The plugin provides the following configuration options:

Key Default Description
enabled true Allow direct returns from resident results
maxEntries 8 Number of resident sessions in this process
maxResidentBytes 134217728 Total amount of resident source bytes
statusFile "" Optional path for real-time diagnostics file

Memory Budget Calculation: The budget is calculated based on compressed source bytes, but the actual occupation is in the heap. Measurements show that a parsed log is approximately 8 times the source bytes. The default 128 MB budget corresponds to roughly 1 GB of heap.

Eviction Order: Written sessions are prioritized over read-only sessions. Among the same level, the least recently read is evicted, and the last one is never evicted.

Behavior and Monitoring

When the plugin runs, it outputs statistics to the log in the following format:

hits=4 ext=0 cold=1
  • hits: Resident hit.
  • ext: Extended resident parse (reading the same session after an append).
  • cold: Full cold read (file structure changed or equivalence could not be proven).

Any situation where equivalence cannot be proven will fall back. In the worst case, it performs exactly as slowly as without the plugin installed—never slower.

Use Cases and Notes

This plugin is suitable for long session scenarios. For short sessions or scenarios with no append operations, an extension count of 0 is normal.

  • Permissions: The plugin runs with the permissions of the current dsh process.
  • License: MIT License.

Summary

Through the steps above, the cold read overhead of DSH long sessions has been eliminated. By utilizing resident parsing and incremental expansion, combined with strict correctness verification, the plugin achieves the goal of parsing long sessions once per process. Refer to the links below for relevant code and documentation.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye