Repository navigation
[PR] fix: replace quadratic link/image regexes with a linear scanner in mdrender - #7377
ranxianglei wants to merge 1 commit into
Conversation
|
(ai: vllm-qwen/qwen3.8-27b) This PR is a duplicate of #7359 — please close it and merge #7359 instead. The issue reporter (@Afloat16) had already submitted #7359 fixing this exact issue (#7358) before I started. I opened this PR in error: I should have screened open Comparison of the two:
Recommendation: close this PR, merge #7359. |
[bot] 🏷 Status update (verified live, 2026-11-20 ~17:00Z) — no change since my last comment; still waiting on your decision. Current live state:
Recommendation (unchanged): close #7377 (this PR) and merge #7359. The technical fix is already complete and verified in #7359; #7377 adds nothing #7359 lacks — its only extra is a broader 16-case exact-semantics test set, which I can fold into #7359 as additive commits if you want (otherwise #7359's existing suite is sufficient). Both remaining actions are yours — I can't close or merge PRs:
8问(给审核者):
待你决策(仅你能做): ① 关闭 #7377(本 PR);② 批准并合并 #7359。可选:是否把 #7377 额外的 16 个精确语义测试以增量 commit 并入 #7359(否则 #7359 现有测试已足够)。 |
[bot] 🏷 This is a re-sync of my own prior comment (the duplicate declaration) — no new request. State is unchanged: #7359 is green and verified, #7377 (this PR) is the stale duplicate. I'm waiting on your close of #7377 + approve/merge of #7359, and won't post further until then. |
…-time regression (#7358) The linear link/image scanner fix for #7358 is already on master (619b529 'fix(web): avoid repeated scans of malformed Markdown links'). This PR's original code change (scanDelimited) is a behaviorally-identical duplicate of master's inlineLinks and was dropped during the conflict rebase; what remains is the additive regression suite (16 exact-semantics cases + 2 bounded-time cases). All 45 tests pass against master's inlineLinks.
f53d916 to
fe95880
Compare
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.11140-pr.7377.5a8497eThis exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr7377.tgz
npm install -g packageInstall instructions are refreshed on each push. |
Conflict resolved — PR is now mergeable (rebased onto master, force-pushed). What I did this run:
Important context — this PR is a duplicate. The #7358 fix is already on master (the merged #7359 /
I can't close or merge — that's your call. I've left it in a clean, mergeable state either way. Status-freshness note: the mirror check-cache still shows the old head 8问(给审核者):
待你决策(仅你能做): ① 关闭本 PR(与已合并的 #7359 / |
Summary
Fixes #7358 — the shared web Markdown renderer's inline link/image regexes backtracked one character at a time from every opening bracket, so a document full of unclosed
[/). Rendering is synchronous on the server (handoff/blog) and the same factory is inlined into the panel IIFE, so a moderate malformed document stalled the calling event loop.What changed
src/web/mdrender.ts: replaced the two regex substitutions (/\[([^\]]+)\]\(([^)\s]+)\)/gand its image twin) with a single linear scannerscanDelimitedthat shares forward pointers for the first]and the first), so every character is visited O(1) times. The two URL-scheme callbacks (image:https?or/__bili/blog-assets/; link:https?or relative) are kept verbatim.tests/mdrender.test.ts: 16 exact-semantics cases + two bounded-time cases (200k unclosed labels under a 2 srunInNewContexttimeout, server and minified detached factory).Behavior
Match semantics are byte-identical to the old regexes — verified over a 20,096-input corpus (20,000 fixed-seed punctuation samples + 96 hand-crafted edge cases) with zero mismatches:
], the url at the first);[label](url)is always consumed;javascript:/data:vectors stay blocked exactly as before.Measured on the issue's fixtures:
[x 40,000.
Verification
npm run typecheckclean,npm run buildgreen.tests/mdrender.test.ts+tests/mdrender-entities.test.ts: 49 pass.mdrender.ts).Notes
kernel/change.