Skip to content

perf(audit-engine): read two columns for the link scan, not every page's HTML - #236

Merged
nc9 merged 3 commits into
mainfrom
perf/site-query-link-scan-projection-1860
Sep 7, 2026
Merged

nc9 merged 3 commits into
mainfrom
perf/site-query-link-scan-projection-1860

Conversation

@nc9

@nc9 nc9 commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Part of #1860 / the OOM incident. Independent of the detach PRs.

createSiteQuery's incoming-link scan walks the pages table twice and reads normalizedUrl and parsedData. It did that through getPages, which is SELECT *: every page's HTML was materialized, and pulled back out of the content store when the column was empty, so the loop could look at parsedData.links.

The HTML is dropped at the end of each batch and the JS heap barely moves, which is why this never looked like a memory problem. The allocator does not give the pages back. Measured over 150 real 959 KB pages, batch 50, three runs, RSS across the call:

RSS growth JS heap growth
before 431 MB (230 / 431 / 492) 0.34 MB
after 88 MB (68 / 88 / 103) 0.30 MB

This is the ~294 MB step a production run showed at rules_site_query, and it is allocator residency rather than anything the audit holds. Shrinking the batch does not help: batch 500 was 581 MB and batch 50 was 431 MB, the same order.

getPageLinkRows is the projection: same table, same ORDER BY, same LIMIT/OFFSET semantics, two columns. tests/page-link-rows-projection.test.ts pins it against getPages row for row, with a second crawl holding the same URLs (so a dropped crawl_id filter fails), a mixed-case pair (so a collation change fails), the paging edges compared by outcome (a nonzero offset with no LIMIT is the same SQLite error in both), an empty stored parse against a missing one, and an assertion that it never touches the content store with the full read as the control.

Byte identity unchanged: the five site-query goldens plus the v1-vs-v2 canonical and streaming goldens pass.

@nc9
nc9 force-pushed the perf/site-query-link-scan-projection-1860 branch from f4706c1 to 48f866e Compare September 7, 2026 11:12
nc9 added 3 commits September 7, 2026 21:19
…e's HTML

`createSiteQuery`'s incoming-link scan walks the pages table twice and reads
`normalizedUrl` and `parsedData`. It did that through `getPages`, which is
`SELECT *`: every page's HTML was materialized, and pulled back out of the
content store when the column was empty, so the loop could look at
`parsedData.links`.

The HTML is dropped at the end of each batch and the JS heap barely moves,
which is why this never looked like a memory problem. The allocator keeps
the pages it grew for it. Measured over 150 real 959 KB pages, batch 50,
three runs, RSS growth across the call:

  before  431 MB   (230 / 431 / 492)
  after    88 MB   (68 / 88 / 103)

The JS heap grew ~0.3 MB either way. This is the ~294 MB step a production
run showed at rules_site_query, and it is allocator residency rather than
anything the audit is holding.

`getPageLinkRows` is the projection: same table, same order, same
pagination, two columns. tests/page-link-rows-projection.test.ts pins it row
for row against `getPages` across three page sizes and asserts it never
touches the content store, with the full read as the control.

Byte identity unchanged: the five site-query goldens plus the v1-vs-v2
canonical and streaming goldens pass.

Signed-off-by: Nik Cubrilovic <[email protected]>
… not a peak

Review findings on the link-scan projection (#1860).

The benchmark's timer sampler claimed a peak. The scan's batches do not
reliably yield to the event loop, and a review reproduced ZERO timer
callbacks across a 280 ms scan, so the number was the endpoint delta wearing
a peak's name. It now reports `rssDeltaMB` and says what it is. The header
also said the heap and RSS figures move together; they do not, and the
separation between them is the entire finding, so it now names them apart.

The equivalence test could not have caught three of the things it claimed:
one crawl cannot catch a dropped `crawl_id` filter, all-lowercase URLs
cannot catch a collation change, and the paging loop never reached limit 0
or an offset past the end. It now runs a second crawl holding the same two
URLs, orders a mixed-case pair BINARY-first, walks the paging edges
comparing OUTCOMES (a nonzero offset with no LIMIT is the same SQLite error
in both reads, and agreeing to fail counts as agreement), and pins an empty
stored parse as "" against a missing one as null.

The `PageLinkRow` doc said the walk never touches these two fields when it
is the HTML it never touches, and both measured comments quoted a single
run; they now quote the three-run medians the commit reports.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the perf/site-query-link-scan-projection-1860 branch from 48f866e to 768fed1 Compare September 7, 2026 11:19
@nc9
nc9 merged commit 2c5b71b into main Sep 7, 2026
13 checks passed
@nc9
nc9 deleted the perf/site-query-link-scan-projection-1860 branch September 7, 2026 11:26
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