DeepSeek Harness Math and Code Rendering Performance Optimization Plugin

Introduction

The DeepSeek Harness client renders all Markdown content at once when handling long conversations. Every math formula must go through the full KaTeX pipeline during React rendering. A conversation containing over 1,300 formulas and 250+ code blocks will saturate the main thread with KaTeX for several seconds, during which scrolling becomes completely unresponsive. dsh-math-perf resolves this performance issue through on-demand rendering and idle-time prefetching.

Plugin Overview

dsh-math-perf is a DeepSeek Harness client plugin developed by maintainer ZhangPotato2022. It injects placeholder components, caches rendered results, and renders formulas and code blocks based on viewport visibility, reducing the initial open time of long conversations from several seconds to near-instantaneous. The plugin runs as a client-side component, modifies the client bundle in the installation directory, and only takes effect locally.

Core Features

1. Formula Rendering by Viewport

The KaTeX wrapper is renamed to __dshMathRender(), and all math nodes are routed through the placeholder component __dshMathLazy. Actual rendering only occurs as the component enters the viewport; cached hits output results directly. The prefetch distance is two screen heights, and a supplementary render queue pass is triggered 220ms after scrolling stops.

2. Code Block Highlighting by Viewport

The Shiki component is renamed to __dshRealCodeBlock, with call sites routed through __dshDeferMount. Code blocks outside the viewport do not execute syntax highlighting, reducing main-thread load.

3. Off-Screen Message Rows Excluded from Layout

The style [data-chat-node-key]{content-visibility:auto;contain-intrinsic-size:auto 240px} is injected, causing off-screen message rows to be excluded from browser layout and painting.

4. Idle Prefetch and Fade-In

requestIdleCallback is used to pre-render queued formulas from the end of the conversation backward, with a per-task budget of ≤6ms and a cap of 400 items. Placeholder blocks are lightweight gray blocks; actual rendering fades in over 160ms.

5. Print Compatibility

On beforeprint, all pending renderable content is flushed in one pass, ensuring printing and export remain unaffected.

Installation and Activation

Install the plugin globally:

npm i -g dsh-math-perf

Add it to your profile:

dsh plugin --profile <profile> add dsh-math-perf

Verify that the profile’s package.json contains the following configuration:

{
  "dependencies": { "dsh-math-perf": "^1.1.1" },
  "dsh": { "profile": { "bundles": [ "...", "dsh-math-perf" ] } }
}

The desktop version requires rewriting the frontend archive:

dsh-math-perf patch

This step only needs to be run once. After future DSH upgrades overwrite the archive, the plugin will automatically re-apply the patch on startup.

Command-Line Usage

Command Description
dsh-math-perf patch [--asar <path>] [--dry-run] Rewrites app.asar in the installation directory; auto-detects install location
dsh-math-perf restore [--asar <path>] Restores the archive from backup
dsh-math-perf extract <file> Exports the unmodified bundle (for debugging)

If the installation location cannot be auto-detected, specify it via --asar or the environment variable DSH_DESKTOP_APP_ASAR.

Probe and Performance Report

12 seconds after page load, the plugin POSTs a JSON payload to its plugin route, which is appended to $DSH_HOME/math-perf-reports.jsonl:

cat ~/.dsh/math-perf-reports.jsonl | tail -3 | jq -r .body | jq

The report includes tasks (longtask list; only entries exceeding 50ms are considered jank), nodes (DOM node count), shiki (number of highlighted code blocks), and mathPending (number of unrendered formulas). Data is stored locally only and never sent externally.

Side Effects

  • Ctrl+F cannot find unrendered formulas: They are not yet in the DOM; scrolling near them will trigger rendering.
  • Cross-screen copy: Unrendered formulas cannot be restored to LaTeX.
  • Placeholder block heights are estimates; scrolling into new areas may cause minor height shifts (browser scroll anchoring offsets most of this).

Uninstall and Rollback

Remove "dsh-math-perf" from dsh.profile.bundles to revert to the original; for the desktop version, additionally run dsh-math-perf restore to restore the archive.

Post-Upgrade Behavior

Upgrades overwrite app.asar, invalidating the patch. The plugin checks the archive on every startup and re-applies the patch in the background:

  • The patch is applied at startup and takes effect on the next launch
  • The patch carries a version marker; it is skipped when versions match
  • Set the environment variable DSH_MATH_PERF_NO_ASAR=1 to disable self-healing
  • If the server-side artifact structure changes, patchBundle() will only emit a warning on match failure and will not write a partial patch

Use Cases and Caveats

This plugin runs with the current dsh process permissions and modifies the client bundle in the installation directory. Review the source code and license before installing. It is well-suited for long conversations with a large volume of formulas and code blocks, but is not ideal for scenarios requiring verbatim copy of every formula.

Ecosystem Context

The DeepSeek Harness philosophy is “everything is a plugin.” The community plugin directory has no official affiliation with DeepSeek or High-Flyer. This article is based on publicly available information; refer to the plugin source code for exact features and behavior.

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

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

Xiaoye