Repository navigation
🌲 fix: Bound Scraped Page Reference Matcher Memory - #739
lia-by-librechat[bot] wants to merge 1 commit into
Conversation
|
Head |
The reference matcher allocated an array per trie node and a map entry per edge, so 6,000 distinct 270-character URLs (1.48 M nodes) grew the heap by 541 MB while building and kept 116 MB. - Hold the automaton in typed arrays, 18 bytes per node: nodes are numbered breadth first from the sorted URLs, so a node's children are one sorted run found by binary search. - Cap it at MAX_MATCHER_NODES (2^21, 36 MiB). The exact node count comes from the sorted URLs before anything is allocated; above the cap the markdown is returned unchanged and the references are still extracted.
be58a9a to
6c5e39c
Compare
|
@codex review the latest head, final review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Stacked on #721. Closes its open P2 finding: #721 (comment)
Change
buildMatcherallocated an array per trie node and a map entry per edge. The automaton now lives in five typed arrays, 18 bytes per node, no object per node. Nodes are numbered breadth first from the sorted URLs, so a node's children are one sorted run (firstChild[node]tofirstChild[node + 1]) found by binary search.MAX_MATCHER_NODES = 2^21(36 MiB). The exact node count comes from the sorted URLs before anything is allocated. Above the capprocessContentreturns the markdown unchanged for the whole page and still returns links, images and videos. No partial rewrite.Measured
buildMatcheron 6,000 distinct 270-character URLs (1.62 MB, 1,482,688 nodes), Node 24.16, one run:d7b136fAt the cap: 2,095,524 nodes, 36.0 MiB, 0.15 s. The Wikipedia fixture needs 19,379 nodes.
processContenton the existing scenarios, best of 3: 2,000 lengths 458 → 314 ms, 6,000 links 227 → 139 ms, 200 suffix URLs 112 → 103 ms, Wikipedia 48 → 30 ms.55,000 random pages (nested, suffix and prefix URLs, parentheses, quotes, titles, non-ASCII, all four types) gave identical output and node counts against
d7b136f. That script is not committed.Tests
src/tools/search/content.test.ts, existing tests unchanged:18 * nodes + 4buffer bytes, full rewrite.MAX_MATCHER_NODESbuilds, one more does not.Checks
npx jest src/tools/search: 16 suites, 276 tests passednpx tsc --noEmit: 0 errorsnpx eslinton the two files: 0 problemsnode scripts/sort-imports.ts --checkon the two files: sortedOffered for @berry-13 to merge into #721 or cherry-pick.