Skip to content

The rule runner builds a profile payload for every rule invocation, whether or not profiling is on #274

Closed

Description

@nc9

runOneRule's finalize (packages/rules/src/runner.ts) does this for every rule invocation:

const passed = ruleChecks.filter((c) => c.status === "pass").length;
const failed = ruleChecks.filter((c) => c.status === "fail").length;
const warned = ruleChecks.filter((c) => c.status === "warn").length;
const elapsedMs = performance.now() - ruleStart;
logger.debug("rule", { ruleId, pageUrl, checks, passed, failed, warned, durationMs, durationUs });

logger.debug discards everything unless SQUIRREL_RULE_PROFILE=1, but the three filter passes and the nine-key object are ARGUMENTS, so they are evaluated on every call regardless. A page-rule pass over gymshark.com (247 pages) makes 48,906 of those calls; a 2,000-page cloud audit makes roughly 400,000.

The fix is to guard on the exported profileRules flag the logger already reads, so the payload is only built when someone is going to look at it.

Found while measuring template fan-out (squirrelscan/repo#1951): the rule bodies the fan-out removes account for 8.9 s of a 12.5 s improvement on that corpus, and this is one of the candidates for the remainder. It is not measured — file this as an observation, not as a sized win, and measure before and after rather than assuming.

Acceptance Criteria

  • The per-invocation profile payload and its three filter passes are not evaluated when SQUIRREL_RULE_PROFILE is unset
  • SQUIRREL_RULE_PROFILE=1 still emits the same [rule-profile] lines, with the same fields, for page and site rules
  • The change is measured on a real corpus before and after, with the number recorded (including "no measurable difference" if that is the answer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3enhancementperformancerulessize: XS

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions