Skip to content

Memoize docstring parsing - #1480

Open
jonludlam wants to merge 3 commits into
ocaml:masterfrom
jonludlam:upstream-perf-doc-memo
Open

Memoize docstring parsing#1480
jonludlam wants to merge 3 commits into
ocaml:masterfrom
jonludlam:upstream-perf-doc-memo

Conversation

@jonludlam

Copy link
Copy Markdown
Member

OxCaml's libraries tend to have a lot of repeated comments due to ppx_template. This PR memoizes the parsing and skips resolving if they don't need it. On Container_intf in base:

  • ~155,000 doc-comment instances
  • only 33 unique doc-comment texts (a 99.98% duplicate rate!)

Impact (on odoc_driver core):

  • odoc user CPU: −13.0%; total CPU −5.2%.
  • Peak single-process RSS −16%; aggregate peak −14%.
  • .odoc files −18%, .odocl files −23% on disk: memoized doc ASTs are physically shared, and Marshal serialises shared structure once. This compounds downstream (less unmarshalling, less memory).

On stock OCaml, there's no cpu usage change, but we do save some space in the odoc and odocl files (~4%).

jonludlam and others added 3 commits September 1, 2026 19:36
OxCaml's ppx_template-heavy libraries attach the same comment text to
thousands of monomorphised copies (Container_intf in OxCaml's base:
~155K comments, 33 unique). Cache parse results keyed on the text —
but only parses that produced no warnings and contain no
location-sensitive constructs (headings, references, {!modules ...}),
since the AST bakes in absolute locations from the first occurrence.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
comment_docs rebuilt every docs element even though linking only
changes references, headings and {!modules ...} lists. Return the
input unchanged when none are present.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@jonludlam
jonludlam force-pushed the upstream-perf-doc-memo branch from 3bd5548 to cb14261 Compare September 1, 2026 19:24
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