1. Extraction — the cleanup, not the parse (medium: -37%). The HTML parse
alone was 6% of a large conversion; the rest was the Markdown writer plus our
own cleanups. tidyMarkdown (extract.go) now does the whole prose cleanup in
one hand-rolled pass per line — fence detection by hand (the fence regexp ran
once per line of prose and was the single most expensive regexp of the
extraction), link-only line detection by scan, trailing-whitespace trim, blank
run collapse — replacing three ReplaceAllString passes per stretch plus the
per-line fence regexp. hasTitleHeading walks the same way instead of two
regexp passes, and sanitize (a full-document regexp with a fast no-match
path) stays for what comes back from the cache.
2. In-page search — no regexp engine (-48% the matcher, -65% the whole
search, allocations x100 down). The query is always a literal (it is quoted
for the engine), so findMatches (search.go) now matches it by hand over a
64-rune window with unicode.ToLower folding, in one pass per line, with a
window reset after each match so matches do not overlap like
FindAllStringIndex. The regexp path stays for absurd queries (> 64 runes).
The search benchmark now spends its time in the re-render of the highlighted
lines instead of the engine: 7675 → 99 allocations per keystroke.
3. Render — Plain without the ANSI parser (-15/16%). plain[i] was built
with ansi.Strip, a full escape-sequence parser, and it cost a sixth of a
large-document render on lines that wr itself painted with SGR and APC markers
(the markers are already stripped by then). stripANSI (render.go) walks
CSI sequences and OSC/DCS strings directly, and returns the line untouched
when it has no ESC at all.