Repository navigation
perf(rules): build the per-rule profile line only when profiling #274 - #925
Conversation
|
Review of #925: the change is small and correct. I found no blocking issues.
Test coverage is good. The tests cover both the profiled and unprofiled paths, and for page and site rules. I haven't run the tests or CI myself. |
runOneRule's finalize built the [rule-profile] payload (three filters over the checks, a nine-key object, a performance.now()) on every rule invocation, and the logger dropped it unless SQUIRREL_RULE_PROFILE was set. It is now built only when profiling. Measured on a real corpus, a 300-page crawl of docs.squirrelscan.com (53,450 rule invocations with template fan-out on). The streamed page-rule pass ran 3 interleaved child processes per arm. Median CPU was 38,491 ms before and 38,931 ms after; median wall was 35,384 ms before and 35,978 ms after. That is no measurable difference: the spread between runs is about 1.1 s. In isolation the removed work is about 5 ms for 53,450 calls. Closes #274 Signed-off-by: Nik Cubrilovic <[email protected]>
c5d16a9 to
fb02adb
Compare
|
Review of #925: I found no blocking issues. The change is correct.
Test coverage is good. It checks the filter-count probe and the field shape for both page and site rules. 🤖 Generated with Claude Code |
|
Triage: nits only. The env var is the single switch because |
The rule runner now builds its per-rule
[rule-profile]payload only whenSQUIRREL_RULE_PROFILEis set. Before,finalizeinrunOneRuleran threefilterpasses, built a nine-key object and calledperformance.now()on every rule invocation, and the logger then threw the result away.Closes #274
Measurement
The corpus is real: a 300-page offline crawl of docs.squirrelscan.com. This box's gymshark crawl takes more than 10 minutes per pass, too long to repeat. The 300-page pass makes 53,450 rule invocations with template fan-out on, counted from the profile lines.
The bench is
apps/cli/scripts/template-fanout-bench.ts --child --arm on, which times the streamed page-rule pass with no network. Each run is its own process. The arms were interleaved (after, before, before, after, after, before) and the load average was 1.4 to 2.5.No measurable difference. Runs of the same arm spread by about 1.1 s. Measured alone, the removed work costs about 5 ms for 53,450 calls, about 0.01% of the pass. The change is still worth having: it removes an allocation and three array passes per rule run that nothing reads.
Acceptance criteria
filterpasses are not evaluated whenSQUIRREL_RULE_PROFILEis unset.tests/rule-profile-274.test.tsruns a child process with a probe rule whose checks countfiltercalls: 0 without the variable (3 on main), 3 with it.SQUIRREL_RULE_PROFILE=1still prints the same[rule-profile]lines with the same fields, for page rules (pageUrl) and site rules (scope: "site"). The same test checks the keys.Checks
SQUIRREL_RULE_PROFILEis a developer profiling variable and the docs do not mention it.Skill impact
None.