Skip to content

perf(markdown): bound live cache retention and reuse parsed blocks - #573

Merged
huichen merged 3 commits into
mainfrom
claude/markdown-memory-profile
Sep 12, 2026
Merged

huichen merged 3 commits into
mainfrom
claude/markdown-memory-profile

Conversation

@huichen

@huichen huichen commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #570/#571, without desktop deployment or disruption of the running Agent:

  • Keep ephemeral live Markdown versions out of the shared static 512-entry parse cache; preserve default static-cache behavior.
  • Retain only the worker's latest projection, reusing it when source is unchanged and only live/settled flags change.
  • Convert already-parsed ordinary mdast subtrees instead of reparsing every block during cold mixed-document projection. Preserve the original isolated-block behavior for reference/footnote definition contexts.
  • Add production-worker compute/heap profiling and explicit impact/limitations documentation.

Evidence

Actual minified production worker in isolated Node processes, identical fixtures, 80 appends, explicit GC, latest response only:

Fixture Retained JS heap after appends Identical-text finalize/resume compute median
56KB / 800-item list 78.171 -> 1.159 MiB (~98.5% lower) 240.561 -> 0.003ms
52KB / 1500-line code block 8.776 -> 0.674 MiB (~92.3% lower) 18.286 -> 0.004ms
481-block mixed document 0.709 -> 0.531 MiB 57.151 -> 0.027ms

Mixed cold projection was 313.229 -> 112.869ms in the final pair; it now reuses the parsed subtrees instead of doing 481 extra block parses. This is one cold sample, not a latency percentile.

No blanket append-throughput improvement is claimed. Mixed append medians were essentially unchanged; code wall median increased ~0.9ms with unchanged coarse CPU median. All caveats, cold-list results, sampled heap high-water and reproducible commands are recorded in desktop/DEV_MD/STREAMING_RENDERING_FIXES.md and streaming-worker-memory-profile.json. These are worker compute/JS heap measurements, not native WebView latency or app RSS.

Validation

  • Five targeted assertions failed on the baseline; all now pass.
  • Mixed-source prefix differential tests bypass the cache in the oracle; definition contexts retain existing behavior.
  • Desktop/shared Markdown TypeScript checks and desktop ESLint passed.
  • Full desktop Vitest: 107 files / 928 tests passed.
  • Production Vite build and production worker check passed.
  • Static cache, existing table incremental projection and streaming lifecycle tests remain green.

@huichen
huichen enabled auto-merge (squash) September 12, 2026 08:05
@huichen

huichen commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator Author

Resolved the shared-parser conflict by retaining origin/main cache:boolean API and adapting desktop callers. Revalidated desktop/shared-package typechecks, ESLint, and all 956 desktop tests. Rebuilt the production worker and reran all three profile fixtures: list retained heap 1.146 MiB and code 0.677 MiB; unchanged-source transitions still avoid parsing. Post-merge verification and its limitations are recorded in the committed profile report.

@huichen
huichen merged commit 3034fcc into main Sep 12, 2026
12 checks passed
@huichen
huichen deleted the claude/markdown-memory-profile branch September 12, 2026 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant