Repository navigation
perf(rules): remove a per-outlier page scan, and measure the rules phases properly - #254
Merged
Merged
Conversation
…#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]>
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]>
…ch 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]>
… 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]>
… 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]>
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]>
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
force-pushed
the
perf/rules-scaling-bench-1910
branch
from
September 7, 2026 21:52
60d0520 to
d49932f
Compare
…bers 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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For squirrelscan/repo#1910 (part of #1028). One rule fix, two scripts.
Nothing measured is quadratic in page count, but one thing was quadratic in the code, and the fixture had to be rebuilt twice before it could see it.
The fix, and why it buys nothing today
integrity/template-discontinuitybuilds a signal context per outlier on the v1 path and looked the page up withpages.find(...). With an outlier sharefthat isf·nscans ofnpages: quadratic in page count, linear in the share. It never runs on the streamed path, which reads a map of page-time signals, and never on a site with no outliers. It is a lazily built, first-wins map now.Minimum of five runs each, on a quiet machine. There is no measurable win, and an earlier version of this PR claimed one. It reported 501 ms against 201 ms on the last row; that was a loaded machine exaggerating a cache-hostile scan. At the largest share the rule can be given — one page in three, because at one in two the baseline absorbs both groups' markers and the rule reports no outliers at all — 2,500 pages is about a million string compares inside a 215 ms rule.
The
f·n²term is real and the map removes it. The change stands on that and on costing one O(n) build on outlier runs against one O(n) scan per outlier, not on a number. Both figures are inbenchmarks/2026-09-perf-program.md, the withdrawn one included.Two behaviour details the first version of the fix got wrong, both caught in review:
new Map(pages.map(...))keeps the LAST entry for a repeated url wherefindreturned the FIRST, which flips this rule from info to fail when a benign page and a compromised one share one, andSiteData.pagesis caller-supplied and not deduplicated. And building the map before the similarity check made every consistently themed v1 site pay an O(n) allocation for nothing.The phases
14.2 KB mean at #1910's template shares, quiet machine, per page in ms:
Slopes across 6.3x: page rules n^1.05, site rules n^0.97, parsePageRecord n^0.93, universe n^0.99, v1 rules n^1.11. Per site rule, the streamed arm totals n^0.86 and the v1 arm n^1.22; the most superlinear on v1 are the link rules,
links/orphan-pagesn^1.46 andlinks/weak-internal-linksn^1.41, which readsiteQueryon the streamed path and walk parsed link arrays on v1.Against the issue's criteria: page-rule per-page cost is flat within 12% on the streamed path and v1's rules phase within 22%, both inside the 25% band.
parsePageRecordper page falls rather than rising.parsePageRecordper page does not rise.Two measurement defects worth knowing about
Both produced confident wrong answers in earlier drafts of this PR.
The profiler rounds every invocation to whole milliseconds. A site rule runs once per audit and takes tens of ms, so rounding costs it nothing. A page rule runs once per page, 495,000 samples at 2,500 pages, and summing them buries sub-millisecond work at zero while a rule that crosses 1 ms on heavier pages jumps a whole unit. That artifact produced an earlier 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 counts page-rule invocations now and reads page-rule cost from the phase spans.
Three things reached the network or the clock, and no config switch I wrote stopped them until the fourth review round.
security/http-to-httpsprobes sample URLs over HTTP with staggered sleeps: at 400 pages it was 508 ms of a 518 ms site phase, so the entire site phase was one rule waiting on sockets and an earlier draft concluded from it that site rules were "dominated by a fixed cost". The soft-404 confirmation pass re-fetches candidates with a sleep between same-host requests, and my first attempt to disable it wrote a root-level key while both engine paths readconfig.integrity.soft404_confirm— so it was on for every measurement until it was nested correctly. Both are excluded now, which also means these numbers are about the remaining rules and not about production rules-phase latency.Why the fixture took three attempts
A negative result is only as good as its corpus, and each version let a rule take an early exit and report a flat line that meant nothing.
The last one is the instructive one. The divergent pages scored 0.258 against the rule's 0.2 threshold, so it reported "all pages share the site's common template". Three separate reasons: they still resolved
bench.testfrom 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 declares CSS variables now, 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 corpus also has pages nothing links to, hubs of 120 links, 4xx pages, noindex pages, off-page canonicals and schema on four templates, each gating a branch a uniform corpus skips.
What this does not claim
A + BnfromA + Bn + Cn²over a narrow range, which is why the per-page columns are printed and are the thing to read.Goldens unchanged: collector-rules, canonical, streaming, pre-rules, report-stream v2, and the rules package's integrity suite.