Skip to content

perf(cli): run the audit's post-crawl phases on the streaming pipeline - #252

Merged
nc9 merged 3 commits into
mainfrom
perf/cli-streaming-pipeline
Sep 7, 2026
Merged

nc9 merged 3 commits into
mainfrom
perf/cli-streaming-pipeline

Conversation

@nc9

@nc9 nc9 commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Wires the squirrel CLI's post-crawl audit phases onto the streaming pipeline the hosted runtime has used since #1860, so a local audit's memory is bounded by the batch instead of by the page count. Private issue #1913.

The problem

The CLI still ran the resident pipeline. storage.getPages(crawlId) materialized every crawled page, buildSiteContext parsed each one into a live DOM, and that single array was held through the external-link check, the resource-asset fetch, the cloud prefetch, tech detect and the whole rules phase. Then reconstructReport read every page a second time.

Retained heap grew about 1.5 MB per crawled page. Max resident set size read flat across the same runs, because on a machine under memory pressure the macOS compressor absorbs the growth: at 2,500 pages the process held 3.9 GB of heap while "resident" said 1.4 GB.

What changed

Every phase after the crawl now walks the pages table in byte-budgeted batches and drops each batch's DOMs before reading the next. No engine code was copied; the CLI calls the same functions the container does, and two seams were added to runStreamingPreRules for the things only the CLI needs:

  • onBatchContext, so a caller can run its own collectors inside the walk while the batch's DOMs are live.
  • resolveBulkChecker, so the paid dead-links spend confirmation still lands before the link phase instead of in the middle of its progress output. The resident path had the link count up front from a whole-crawl context; this pass only has it once the walk ends.

The CLI-side consumers that used to read a whole-crawl site context now collect during that walk: the cloud-prefetch payloads, a bounded tech-detect page sample, the dead-links link count and the smart-audits page list. reconstructReport's page pass is batched the same way.

Strings kept out of a parsed page are detached from it. A 6 KB text excerpt is a slice of the page's HTML, and in JSC a retained slice pins the buffer it was cut from, so one excerpt per page would have put the page-count-scaled term straight back. The resident path never had to care, because it was holding the page anyway.

Numbers

Interleaved cold runs on a 6-template synthetic estate (mean 128 KB/page, 10% a real 982 KB product page), fresh content store per stage, same page bytes both sides. heapUsed is process.memoryUsage() after Bun.gc(true) at exit, not RSS.

pages wall (resident → streamed) end heapUsed (resident → streamed) max RSS
400 47s → 47s 685 MB → 265 MB 865 → 786 MB
1,000 194s → 128s 1,662 MB → 565 MB 1,300 → 1,108 MB
2,500 502s → 177s 3,902 MB → 996 MB 1,463 → 1,688 MB
1,000 warm 87s → 72s 1,651 MB → 561 MB 1,944 → 1,734 MB

Wall time improves rather than regressing. The issue expected a 16% streaming penalty, measured on the container. Locally the resident path pays for its own 1.6 to 3.9 GB in collector and compressor work, and that costs more than the extra parse per page the streamed walk adds. At 400 pages, where the resident heap still fits comfortably, the two are identical.

The remaining slope is about 0.3 to 0.5 MB per page, down from 1.5. It is the engine's DOM-free scalar page universe, which is v1's page set and load-bearing for byte identity, not something this change can remove.

Report parity

Reports are identical at 400, 1,000 and 2,500 pages, after stripping only the fields that are per-run by construction: crawl id, timestamps, durations, load times and the ephemeral test server's port.

One caveat worth stating. At 2,500 pages the raw diff showed 14 findings' difference, all of them perf/ttfb, which grades the server's response time. The resident run was under 3.9 GB of pressure and starved the local server past the 600 ms threshold on 14 pages. Excluding that one wall-clock rule, the two reports are byte-for-byte equal. Nothing else differs.

The engine's canonical-vs-streaming golden and its 518-page baseline stay green, as do the CLI's own suites.

Against the acceptance criteria

Read these before reading "flat" literally anywhere above.

Rules run through the streaming pipeline rather than materialising every page. Met. Nothing after the crawl holds a page-count-scaled structure of pages, and the two remaining whole-crawl reads (the site context and the report's own getPages) are gone.

End-of-run heapUsed flat within the batch bound across 1,000 and 2,500 pages. Partially met, and worth being precise about. DOM residency is batch-bounded, which is the part that produced the 1.5 MB per page. What remains is not flat: 265 MB at 400 pages, 565 MB at 1,000, 996 MB at 2,500, a slope of roughly 0.3 to 0.5 MB per page against the resident path's 1.5, and decelerating rather than linear.

That residual is the engine's DOM-free scalar page universe, streamParsedUniverse's pageDataMap. It is v1's page set and the streaming golden depends on it, so it cannot be dropped here without changing the report. The per-sub-phase trace shows it is the only term still growing: at 1,000 pages the universe pass reaches 285 MB and every phase after it, page-rules, site-query, site-rules and assemble, sits at 287 MB.

[stream] universe end    heapUsed=285MB external=51MB rss=915MB
[stream] page-rules end  heapUsed=287MB external=56MB rss=798MB
[stream] site-rules end  heapUsed=287MB external=54MB rss=853MB
[stream] assemble end    heapUsed=287MB external=36MB rss=853MB

Report byte-identical on the golden fixture and the 518-page baseline. Met, both green.

Report identical end to end. Met at 400 and 1,000 pages with no exclusions. At 2,500 the raw diff showed 14 findings differing and every one of them was perf/ttfb, which grades the server's response time rather than anything about the page. The resident run was carrying 3.9 GB and starved the local test server past the 600 ms threshold on 14 pages; the streamed run did not. Excluding that one wall-clock rule the two reports are byte-for-byte equal. Nothing else differs, at any size.

Cold and warm wall-clock no worse. Met, and better: no size regressed, and 1,000 and 2,500 pages improved by 34% and 65%.

The batch dial is the one the cloud uses and its default is stated. Met, SQUIRREL_STREAM_BATCH_BYTES, 48 MB, see below.

Memory verified with heapUsed rather than max RSS alone. Met. Every figure here is process.memoryUsage() after Bun.gc(true). Max RSS is quoted alongside only to show it is the misleading one: at 2,500 pages the resident path held 3,902 MB of heap while RSS read 1,463 MB.

The dial

SQUIRREL_STREAM_BATCH_BYTES sets the byte budget, 48 MB of raw HTML by default, the same name and default the container reads. SQUIRREL_STREAM_BATCH_PAGES pins an exact page count instead. Both clamp.

Do not turn the budget below roughly a dozen pages' worth. Measured on real ~1 MB pages, peak is a ~300 MB floor plus about 3.5 MB per page of batch, and under about 12 pages the same crawl becomes several times as many read-parse-collect cycles whose churn sets a higher high-water than a larger batch does.

A value that is not a plain integer is now refused and named rather than partially parsed: SQUIRREL_STREAM_BATCH_BYTES=48mb through parseInt is 48 bytes, which clamps to a 1 MB batch and looks like the fix not working.

Review findings, all fixed

An adversarial review of the first commit found three real defects, fixed in the second:

  1. The external-link phase lost the global dead-link cache. The resident entry point reached for getGlobalLinkCache() inside itself; the collected-links entry point takes it as an argument and reads an absent one as "no caching". Every re-audit would have re-checked every external link and resubmitted already-known URLs to the paid bulk checker.
  2. The report's per-page fields still pinned whole pages. meta, og, twitter, schema and the h1 texts are HTML slices. 77.5 MB retained across 80 ~1 MB pages attached, 2.1 MB detached.
  3. Sitemap status checks silently stopped at 2,000 URLs. The engine's asset pass capped the orphan list at REPORT_LIMITS.maxPages before the configured resource limit applied, so on a 3,000-page crawl with more than 2,000 uncrawled sitemap URLs a 404 at position 2,001 was never fetched and crawl/sitemap-4xx reported a pass. Candidates are now bounded by the resource limit alone; the arrays that travel on the report stay capped. The cloud is unaffected, it passes resourceCheckMaxItems = 100.

Reports stayed identical at 400 and 1,000 pages after these fixes, with end heapUsed unchanged.

Tests

New: streamed payload parity (the collectors versus the whole-array builders at batch sizes 1, 4, 7 and 1000, including the case where the home page lands in a later batch than the sample it must lead) and the batch dial.

Run green: the full CLI suite (1,960 tests), and in the engine the canonical-vs-streaming golden, the streaming pre-rules golden, the 518-page baseline, the detach suites and batch sizing.

Not in scope

squirrel analyze, which runs the resident path over an already-stored crawl, is unchanged. The engine's container-side cloud-prefetch replica has the same un-detached page-payload retention this fixes on the CLI side; that is a separate change.

Nik Cubrilovic added 3 commits September 8, 2026 05:33
…#1913

The CLI audit was still the resident pipeline: one buildSiteContext over every
crawled page, a parsed page plus its DOM held through the whole rules phase, and
a second whole-crawl getPages in the report. End-of-run retained heap grew about
1.5 MB per crawled page while max RSS read flat, because the macOS compressor
absorbed it.

Every post-crawl phase now walks the pages table in byte-budgeted batches and
drops each batch's DOMs before reading the next, using the same engine functions
the hosted runtime has run since #1860 rather than a second implementation:

- runStreamingPreRules replaces buildSiteContext + checkExternalLinksOnStorage +
  fetchResourceAssets. Two seams were added to it for the CLI: onBatchContext,
  for a caller's own page-time collectors, and resolveBulkChecker, so the paid
  dead-links spend confirm still lands before the phase rather than inside its
  progress output.
- runStreamingRules replaces runRulesOnStorage.
- reconstructReport's page pass is batched.
- The cloud-prefetch payloads, the tech-detect page sample, the dead-links link
  count and the smart-audits page list are collected during the pre-rules walk.
  Payload strings are detached from the page they were sliced off (#240): a
  6 KB text excerpt pins a whole page, which the resident path never had to
  care about and a streamed walk does.

Batch size comes from SQUIRREL_STREAM_BATCH_BYTES (48 MB of raw html by
default), the same dial and default the container reads, with
SQUIRREL_STREAM_BATCH_PAGES to pin a page count. A value that is not a plain
integer is refused and named rather than silently partially parsed, because
"48mb" through parseInt is 48 BYTES and clamps to a 1 MB batch.

Measured on a 6-template synthetic estate (mean 128 KB/page, 10% a real 982 KB
product page), interleaved cold runs, heapUsed sampled after Bun.gc(true):

  pages   wall            end heapUsed
    400   47s  ->  47s    685 MB ->   265 MB
  1,000  194s  -> 128s  1,662 MB ->   565 MB
  2,500  502s  -> 177s  3,902 MB ->   996 MB

Wall time improves rather than regressing: the resident path's own 1.6-3.9 GB
costs more in collector and compressor work than the streamed walk's extra parse
per page. Reports are identical at all three sizes, and at 2,500 pages the only
difference between the two runs is perf/ttfb, which grades the server's response
time and saw a machine under 3.9 GB of pressure.

Signed-off-by: Nik Cubrilovic <[email protected]>
Found by an adversarial review of the port, all three verified in code:

- The external-link phase lost the global dead-link cache. The resident entry
  point (checkExternalLinksOnStorage) reached for getGlobalLinkCache() itself;
  the collected-links entry point takes it as an argument and reads an absent
  one as "no caching". Every re-audit would have re-checked every external link
  and resubmitted already-known urls to the PAID bulk checker.

- The report's per-page fields were still pinning whole pages. meta, og,
  twitter, schema and the h1 texts are slices of the page's html, and in JSC a
  retained slice holds the buffer it was cut from. The resident path was holding
  the page anyway; here the batch is dropped right after, so each kept title held
  its megabyte. Measured on ~1 MB pages: 77.5 MB retained across 80 pages
  attached, 2.1 MB detached. One copy per page of five small objects.

- Sitemap status checks silently stopped at 2,000 urls. The engine's asset pass
  capped the orphan list at REPORT_LIMITS.maxPages before the configured
  resource limit was applied, so on a 3,000-page crawl with more than 2,000
  uncrawled sitemap urls a 404 at position 2,001 was never fetched and
  crawl/sitemap-4xx reported a pass. The candidates are now bounded by the
  resource limit alone; the arrays that travel on the report stay capped. The
  cloud is unaffected, it passes resourceCheckMaxItems = 100.

Reports stay identical to the resident path at 400 and 1,000 pages, and end
heapUsed is unchanged at 266 MB and 563 MB.

Signed-off-by: Nik Cubrilovic <[email protected]>
… dials #1913

The batch dials are user-facing and had no page. Added to the debug guide,
next to tracing, because that is where someone lands when an audit is slow or
large: what the batching does, the two env vars with the container's names and
default, why turning the budget down usually makes peak memory worse, and the
opt-in per-sub-phase heap line. Says to read heapUsed rather than rss, since
macOS compression makes the resident figure stop tracking what is held.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the perf/cli-streaming-pipeline branch from 49ceca8 to 97141d4 Compare September 7, 2026 19:33
@nc9
nc9 merged commit 1b9d7af into main Sep 7, 2026
13 checks passed
@nc9
nc9 deleted the perf/cli-streaming-pipeline branch September 7, 2026 19:40
nc9 added a commit that referenced this pull request Sep 7, 2026
…ng their pages (#255)

* fix(audit-engine): stop the container's cloud-prefetch payloads holding their pages #253

buildCloudPagePayloads keeps a 6 KB text excerpt per page, plus a title, a
description and up to twenty headings. Every one is a slice of that page's html,
and in JSC a retained slice pins the buffer it was cut from, so the payload list
held the whole crawl as UTF-16 for the length of the prefetch. That is the
page-count-scaled term the streamed pre-rules walk exists to remove: the walk
drops each batch as soon as the collectors have absorbed it, and nothing else is
keeping those pages alive.

truncateUtf8Bytes is not a detach. It returns text.slice(0, maxBytes) unchanged
whenever the slice already fits the byte budget, which is every all-ASCII page,
so the excerpt came back still attached. Pinned as its own test so the next
reader does not mistake it for one.

Measured with the #250 retention harness on per-page-distinct 4 MB pages, 24
pages, `external` with a retain-nothing control subtracted:

  attached  +186 MB
  detached    +3 MB

The blocklist urls and selectors and the gaps seeds get the same treatment.
Those three are capped (1,500 / 500 / 50) so their worst case was bounded by the
cap rather than by page count, but a capped list of 1,500 attached urls still
pins up to 1,500 pages.

Payloads are unchanged: same fields, same values, same order, asserted directly
and covered by the CLI-vs-container prefetch parity test. The CLI's twin of this
code was fixed in #252; this is the container side, which runs on every hosted
audit.

Signed-off-by: Nik Cubrilovic <[email protected]>

* perf(audit-engine): pay the payload detach per unique value, not per occurrence #253

Review follow-up on the commit above. Three cheap wins, no behaviour change:

- The blocklist url and selector sets cap UNIQUE values, but the clone was being
  paid per occurrence. A site that links the same forty hosts and reuses the same
  layout classes on every page has orders of magnitude more occurrences than
  uniques, so the set is now tested before the copy is made. The resulting set is
  identical either way — a duplicate never grew it.

- The container's `cleanSeed` assembles its result character by character and
  returns `parts.join("")`, a fresh string that references no page, so detaching
  a seed there was pure cost. Dropped, with a note saying why the CLI's twin
  still needs one: it builds the same value with split/replace/trim, whose
  results CAN be slices. A real difference between the two files rather than a
  missed case.

- The CLI's twin gets the same dedupe-before-clone, so the two stay in lockstep
  where they should be.

Signed-off-by: Nik Cubrilovic <[email protected]>

---------

Signed-off-by: Nik Cubrilovic <[email protected]>
Co-authored-by: Nik Cubrilovic <[email protected]>
nc9 added a commit that referenced this pull request Sep 7, 2026
Rebasing onto main and re-measuring on a quiet machine with five runs per cell
removed the improvement I had claimed for this change. Correcting it here rather
than quietly restating it.

  integrity/template-discontinuity, v1, minimum of five runs, rebased code

    outlier share   pages    before    after
              10%   2,500    159 ms   154 ms
              33%   1,000     74 ms    71 ms
              33%   2,500    215 ms   225 ms

The earlier 501 ms against 201 ms at the last row was a loaded machine
exaggerating a cache-hostile scan, not the algorithm. At the largest share the
rule can be given — one page in three, since at one in two the baseline absorbs
both groups' markers and there are no outliers at all — 2,500 pages is about a
million string compares inside a rule that takes 215 ms. The `f*n^2` term is
real and the map removes it, but it is not what dominates at any size this
fixture can reach, and the change stands on that rather than on a number.

Adds the rows to benchmarks/2026-09-perf-program.md per the standing rule,
including the withdrawn measurement, because a record that keeps only the
flattering runs is worth nothing.

Also corrects the benchmark's own framing: #252 moved the CLI's `audit` onto the
streamed pipeline, so v1 now serves `squirrel analyze` rather than being "the
CLI path". The arm that measures superlinear is the one being retired.

Refs squirrelscan/repo#1910, #1028.

Signed-off-by: Nik Cubrilovic <[email protected]>
nc9 added a commit that referenced this pull request Sep 7, 2026
…ases properly (#254)

* perf(audit-engine): a rules-scaling benchmark, and the numbers it gets #1910

Two scripts, no production change. #1910 reports site rules at n^2.0, page rules
at n^1.6 and per-page PARSE cost rising from 5.5 to 40 ms, and asks for the
measurement to be redone under conditions where those can be believed. It does
not reproduce.

Three things the original could not control, and this does. CONTENTION: #1910's
own caveat says its 2,500 row was 589s wall against 360s CPU and its 5,000 row
2,236s against 1,023s, on a 16 GB box doing 150 MB/s of swap at load average 13.
THE CONTENT STORE: #1908's scan-per-insert makes a crawl quadratic in its own
page count, so these fixtures keep html in the crawl DB and never touch the
global store. THE PATH: the CLI runs v1 and the cloud runs the streamed pass,
and #1910 measured the CLI, so both are timed.

Mixed estate at #1910's template shares, ~13 KB mean, quiet machine:

  pages  universe/pg  pageRules/pg  siteRules/pg  v1 parse/pg  v1 rules/pg
    400         0.39          5.89          1.29         0.23         6.15
   1000         0.36          5.38          0.57         0.17         5.85
   2500         0.37          5.76          0.32         0.17         6.76

Across 6.3x: universe n^0.97, page rules n^0.99, SITE RULES n^0.23, v1 parse
n^0.82, v1 rules n^1.05. Site rules are sub-linear, not quadratic — 518 to
790 ms while pages go 400 to 2,500 — because the phase is dominated by a fixed
cost rather than by anything per-page.

Page weight does not change it. At weight 5 (~100 KB mean, script-heavy product
pages, which brackets #1910's 128 KB estate) over 400 to 1,600: page rules
n^0.98, site rules n^0.14, v1 rules n^1.17.

Per-rule at 400 against 2,500 (6.25x, so linear is 6.25x and quadratic 39x):
the largest single site rule is security/http-to-https at 508 to 790 ms, which
is 1.6x and effectively fixed. The most superlinear are eeat/affiliate-disclosure
12.0x on a 24 ms base, local/nap-consistency 9.7x, schema/coverage-outlier 8.6x,
integrity/orphan-page 8.1x and url/slug-convention 7.9x — n^1.05 to n^1.55, none
of them near quadratic and none of them large.

Refs squirrelscan/repo#1910, #1028.

Signed-off-by: Nik Cubrilovic <[email protected]>

* fix(audit-engine): the site-rule number was the network, not the rules

Review found the first version of this benchmark measuring the wrong thing, in
two ways that changed the answer.

`security/http-to-https` probes sample URLs over HTTP with staggered sleeps, and
none of the cloud, intel or external-link switches turns it off. At 400 pages it
was 508 ms of a 518 ms site phase: the phase was one rule waiting on sockets,
and every other site rule's scaling was invisible under it. My "site rules are
sub-linear, dominated by a fixed cost" was a description of that probe. It is
excluded by default now, the excluded set is printed, and site rules come out
LINEAR rather than sub-linear.

The "v1 parse" column was not `parsePageRecord`. With stored `parsedData`,
`buildSiteContext` re-parses the DOM and deserializes the rest, which is a
different and cheaper thing than the full extraction #1910 reports rising from
5.5 to 40 ms per page. Both are timed now, and named `hydrate` and
`parsePageRecord` so neither can be read as the other.

Also fixed: every measurement runs in its OWN child process, so no arm inherits
another's warm JIT, parser structures or SQLite cache and the sizes cannot warm
each other; v1 is split into hydrate and rules rather than reported as one
number, since a near-linear total cannot rule out a superlinear site component
inside it; `site-query` is printed instead of collected and discarded; the
`--profile` flag now actually sets the environment variable the logger reads;
and the slope guards against equal endpoints, which printed Infinity.

The fixture was wrong about itself. Its shares were 10/10/20/30/20/10, not the
10/10/30/30/10/10 the comment claimed, and it reported neither its real mean
page size nor the ~4.5x rather than 7x that its weight dial actually moved. The
mix is now derived from a table so it cannot drift from the prose, the builder
prints the mean it produced, and the corpus has the variety a negative result
needs: pages nothing links to, hubs of 120 links, 4xx pages, noindex pages,
off-page canonicals and schema on four templates rather than one. A uniform
corpus lets orphan detection skip its hidden-page branch and leaves
coverage-outlier with no group to compare, and a flat line from that says
nothing.

Refs squirrelscan/repo#1910, #1028.

Signed-off-by: Nik Cubrilovic <[email protected]>

* fix(audit-engine): give the fixture an outlier population and the bench its own split

Review again, and the fixture was hiding the one plausibly quadratic path in the
site rules.

`integrity/template-discontinuity` fingerprints each page — asset hosts,
stylesheet hrefs, body classes, nav and footer presence — against a site
baseline, and gives up immediately when no baseline exists. Every page in the
fixture had the SAME fingerprint, so the rule returned "no shared theme" and
never reached the branch that costs anything: on v1 that branch does
`pages.find(...)` PER OUTLIER, which is quadratic in the outlier share. The
fixture now has a real theme and a tenth of pages off it. The branch runs, and
at that share it measures n^1.27 rather than n^2.

The benchmark no longer needs a human to compute its own headline. With
`--profile` it parses each child's profiler output itself and prints the
page-scope and site-scope totals per arm, plus the top site rules, with the
slope. The previous n^1.24 came from undocumented processing outside the tool.
It also states in the header that those per-rule sums are overlapping wall
durations under bounded concurrency, so they add to more than the phase they
came from and must never be read against one.

The soft-404 confirmation pass is disabled too. It re-fetches every flagged
candidate with a sleep between same-host requests, `benchConfig` did not turn it
off, and although it does not fire on these fixtures another database would make
it the measurement — the same way `security/http-to-https` already had been.

The interesting result changed. Page rules are flat on the streamed path,
n^1.01, and n^1.47 on v1 over the same pages on the same machine; v1's total
rules phase goes from 6.42 to 8.47 ms per page across 400 to 2,500 while the
streamed page phase stays within 6% of 7 ms. The two paths differ in whether
every page's DOM is resident while the page rules run.

Refs squirrelscan/repo#1910, #1028.

Signed-off-by: Nik Cubrilovic <[email protected]>

* perf(rules): look the outlier's page up in a map, not by scanning the page set

The one genuinely quadratic thing #1910's phases were hiding, plus the two
measurement defects that were hiding it.

`integrity/template-discontinuity` builds a signal context per outlier on the v1
path, and looked the page up with `pages.find(...)`. With an outlier share f
that is f*n scans of n pages: quadratic in page count, linear in the share. It
never ran on the streamed path, which reads a map of page-time signals, and it
never ran on a site with no outliers. A map, built only when v1 will use it.

  integrity/template-discontinuity, v1, minimum of three runs

    pages    before    after
      400     22 ms    24 ms
    1,000     67 ms    78 ms
    2,500    229 ms   185 ms

  n^1.28 before, n^1.11 after; 19% at 2,500 pages. Small now because at a 10%
  share the quadratic term is 312k comparisons against a linear part that still
  dominates. At 10,000 pages that term is 5M while the linear part grows 4x,
  which is the size #1028 is aimed at.

THE FIXTURE COULD NOT SEE IT. Its divergent pages scored 0.258 against the
rule's 0.2 threshold, so it reported "all pages share the site's common
template" and never entered the branch. Three things were wrong, and each is
worth knowing: the divergent pages still resolved `bench.test` from their
canonical link and relative image srcs, so host Jaccard was 1/3 rather than
near 0; NEITHER side declared CSS variables, and the Jaccard of two empty sets
is 1, so that term paid full weight TO SIMILARITY; and both sides had a `<nav>`,
so half the chrome term matched. The baseline now declares CSS variables, the
divergent pages spread assets over three foreign hosts and wrap their links in a
div, and they score 0.05. Verified: 40 outliers at 400 pages, exactly the 10%
intended.

THE PROFILER ROUNDS EVERY INVOCATION TO WHOLE MILLISECONDS. A site rule runs
once per audit and takes tens of ms, so that costs it nothing. A page rule runs
once per page — 198 rules over 2,500 pages is 495,000 rounded samples — and
summing them buries sub-millisecond work at zero while a rule crossing 1 ms on
heavier pages jumps a whole unit. That artifact produced a previous claim here
that v1's page rules were n^1.47 against streaming's n^1.01; unrounded timings
of the same invocations put both near n^1.0. The benchmark now COUNTS page-rule
invocations instead of summing them, and page-rule cost is read from the phase
spans, which are unrounded.

Also: the soft-404 confirmation pass is disabled alongside the http-to-https
probe, since it re-fetches candidates with a sleep between same-host requests;
an arm whose attempts all failed prints "failed" rather than a measured zero;
and the per-rule rows now come from the single attempt named in the header
rather than mixing a total from one attempt with rows from another.

Goldens unchanged: collector-rules, canonical, streaming, pre-rules,
report-stream v2 and the rules package's integrity suite.

Refs squirrelscan/repo#1910, #1028.

Signed-off-by: Nik Cubrilovic <[email protected]>

* fix(rules): keep the FIRST page for a repeated url, and build the map only on demand

Review of the previous commit. Three corrections, and a measurement that finally
shows what the change is worth.

`new Map(pages.map(...))` keeps the LAST entry for a repeated url; `pages.find`
returned the FIRST. `SiteData.pages` is caller-supplied and not deduplicated, so
with a benign page and a compromised one sharing a url this rule's verdict
flipped from info to fail. Built first-wins now.

The map was also built before the similarity check, so every v1 site reaching
that point paid an O(n) allocation including consistently themed sites with no
outliers at all — the opposite of what the comment beside it claimed. It is
lazy: the first outlier builds it, a site with none never does.

And the benchmark's soft-404 override did nothing. It wrote a root-level
`soft404_confirm` while both engine paths read `config.integrity.soft404_confirm`,
so the pass has been enabled in every measurement, free to add fetches and sleeps
to v1's rules duration on any database with candidates. The default is
`enabled: true`; the nested override now actually turns it off.

WHAT THE FIX IS WORTH, and the honest version is two numbers, because the term
is linear in the outlier SHARE as well as quadratic in page count. The fixture
gained `--divergent-in` for exactly this. At one page in two the baseline flips
and there are no outliers at all, so one in three is as far as it goes:

  integrity/template-discontinuity, v1, minimum of three runs

    outlier share   pages    before    after
              10%     400     22 ms    22 ms
              10%   1,000     67 ms    93 ms
              10%   2,500    229 ms   199 ms
              33%   1,000     93 ms   111 ms
              33%   2,500    501 ms   201 ms

At a realistic 10% the win is inside the run-to-run noise at these sizes, and I
am not going to claim it. At 33% it is unmistakable: 1,000 to 2,500 pages costs
n^1.84 before and n^0.65 after, and 2,500 pages goes from 501 ms to 201 ms. The
change is justified by the asymptotics rather than by today's saving, and it
costs nothing to make.

Refs squirrelscan/repo#1910, #1028.

Signed-off-by: Nik Cubrilovic <[email protected]>

* docs(rules): three accuracy corrections from the final review round

No behaviour change beyond the reporting.

"Costs nothing" was not quite true: an outlier run pays one O(n) map build. It
still replaces one O(n) scan PER OUTLIER, which is the point, and the comment
now says both halves.

The fixture printed its variety counts with `Math.floor(N / k)`, which ignores
the residue offset: at 400 pages it claimed 4 4xx and 17 noindex where it had
written 5 and 18. They are counted while generating now. It also records why
`--divergent-in 2` is useless: the baseline's majority threshold is inclusive,
so at one page in two it absorbs BOTH groups' markers, which lifts the divergent
pages from 0.05 similarity to 0.2375, above the 0.2 threshold, and the rule
reports no outliers. I had described that as the baseline "flipping", which is
not what happens.

`hydrate` also included the `getPages` read while the parse arm excluded it, so
the two columns were not measuring comparable boundaries. Renamed
`load+hydrate`.

The fixture header claimed to support "the rules phases are not superlinear in
page count". It supports "this phase did not grow superlinearly here", which is
a smaller thing and the only thing one corpus at three sizes can say.

Refs squirrelscan/repo#1910, #1028.

Signed-off-by: Nik Cubrilovic <[email protected]>

* fix(rules): the template-discontinuity win was machine load, not the map

Rebasing onto main and re-measuring on a quiet machine with five runs per cell
removed the improvement I had claimed for this change. Correcting it here rather
than quietly restating it.

  integrity/template-discontinuity, v1, minimum of five runs, rebased code

    outlier share   pages    before    after
              10%   2,500    159 ms   154 ms
              33%   1,000     74 ms    71 ms
              33%   2,500    215 ms   225 ms

The earlier 501 ms against 201 ms at the last row was a loaded machine
exaggerating a cache-hostile scan, not the algorithm. At the largest share the
rule can be given — one page in three, since at one in two the baseline absorbs
both groups' markers and there are no outliers at all — 2,500 pages is about a
million string compares inside a rule that takes 215 ms. The `f*n^2` term is
real and the map removes it, but it is not what dominates at any size this
fixture can reach, and the change stands on that rather than on a number.

Adds the rows to benchmarks/2026-09-perf-program.md per the standing rule,
including the withdrawn measurement, because a record that keeps only the
flattering runs is worth nothing.

Also corrects the benchmark's own framing: #252 moved the CLI's `audit` onto the
streamed pipeline, so v1 now serves `squirrel analyze` rather than being "the
CLI path". The arm that measures superlinear is the one being retired.

Refs squirrelscan/repo#1910, #1028.

Signed-off-by: Nik Cubrilovic <[email protected]>

* docs(benchmarks): record the three traps behind the rules-scaling numbers

Requested for the #254 entry. Each of these produced a confident wrong answer
before it was controlled, so the record carries them beside the numbers rather
than leaving the next person to rediscover them.

Two rules in the rules phase reach the network and no obvious switch stops them;
soft-404 confirmation in particular needs config.integrity.soft404_confirm, and
a root-level key of that name is silently ignored while the default is enabled.
The rule profiler rounds every invocation to whole milliseconds, which is
harmless for a once-per-audit site rule and fatal across 495,000 page-rule
samples. And a uniform fixture skips the branches that cost anything: the
Jaccard of two empty sets is 1, so a fingerprint term neither side declares pays
full weight to similarity, which is how the quadratic scan stayed invisible.

Plus the one from the table itself: a loaded machine systematically inflates a
cache-hostile scan rather than merely adding noise to it, so minimum-of-N on a
busy box is not a defence.

Refs squirrelscan/repo#1910.

Signed-off-by: Nik Cubrilovic <[email protected]>

---------

Signed-off-by: Nik Cubrilovic <[email protected]>
nc9 added a commit that referenced this pull request Oct 14, 2026
…k unanswered #753

A chunk the bulk checker answers with none of its urls now ends the bulk
pass, like a throw: the remaining urls go to the local per-link checker
straight away instead of each later chunk costing the service's full wait.
A chunk that answers at least one url keeps the pass going.

Tests pin the local fallback for urls the service leaves out (stored with
their local status, a 404 reported as dead by links/dead-links), the stop
after an unanswered chunk, and that partial answers do not stop the pass,
through the engine and through the CLI's own dead-links checker.

Removes the CLI adapter's unreferenced fork of checkExternalLinksOnStorage
and runBulkChecker; the live path has been the engine's since #252.

Signed-off-by: Nik Cubrilovic <[email protected]>
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