Skip to content

perf(validate): read the cycle already run instead of running another one - #98

Merged
thiagoluga merged 1 commit into
mainfrom
perf/one-scan-fewer-in-the-validation
Aug 18, 2026
Merged

thiagoluga merged 1 commit into
mainfrom
perf/one-scan-fewer-in-the-validation

Conversation

@thiagoluga

Copy link
Copy Markdown
Owner

The shortfall accounting launched a second full scan just to read three counters. On the container's real WordPress a full scan costs about eight minutes, and three checks added in one day — #87's, #91's and #93's — each did that. make validate-engines went from roughly a quarter of an hour to nearly an hour.

That matters more than it looks. A validation nobody has an hour for is one that stops being run, and this script's entire value is that it gets run before trusting a scan. Slowness is how it fails in practice, not wrongness.

The counters were already on screen

Since #92 the text report prints each engine's gaps and notes on their own lines:

      skipped: vanished_before_hashing=2
      notes: outside_requested_scope=853, unknown_rule=260

and $scan_output was captured forty lines earlier in the same section. Same cycle, same numbers, no second walk.

unknown_rule is deliberately not counted as an excuse for a shortfall: the finding it describes is in the report, so it explains nothing about one that is missing. Verified against a realistic sample rather than assumed — outside_requested_scope=853 plus vanished_before_hashing=2 sums to 855, and the unknown_rule=260 on the same line stays out of it.

Six full scans, now five

The remaining pair in the evasion section is inherent: comparing the terminal against the JSON needs one invocation of each, and they have to be adjacent so they describe the same state.

The other three are each doing a distinct job — the main cycle, the post-quarantine cycle with observation_mode off, and the memory-peak measurement — so they stay.

Self-inflicted, and worth saying so

I added all three of the expensive checks in this session, and each looked cheap in isolation. The cost only became visible when a run sat at fifty-eight minutes and I went to find out whether it had hung. It had not — it was doing exactly what I told it to, three times over.

… one

The shortfall accounting launched a second full scan just to read three
counters. On the container's real WordPress a full scan costs about eight
minutes, and three checks added in one day each doing that took
`make validate-engines` from roughly a quarter of an hour to nearly an hour.

That matters more than it looks. A validation nobody has an hour for is one that
stops being run, and this script's whole value is that it gets run before
trusting a scan. Slowness is how it fails in practice — not by being wrong.

The counters were already on screen. Since #92 the text report prints each
engine's gaps and notes on their own lines, and $scan_output was captured forty
lines earlier in the same section. Same cycle, same numbers, no second walk.

unknown_rule is deliberately not counted as an excuse for a shortfall: the
finding it describes IS in the report, so it explains nothing about one that is
missing. Verified against a realistic sample rather than assumed —
outside_requested_scope=853 plus vanished_before_hashing=2 sums to 855, and the
unknown_rule=260 on the same line stays out of it.

Six full scans, now five. The remaining pair in the evasion section is
inherent: comparing the terminal against the JSON needs one invocation of each.
@sonarqubecloud

Copy link
Copy Markdown

@thiagoluga
thiagoluga merged commit 0c94f19 into main Aug 18, 2026
10 checks passed
@thiagoluga
thiagoluga deleted the perf/one-scan-fewer-in-the-validation branch August 18, 2026 20:38
@thiagoluga

Copy link
Copy Markdown
Owner Author

Measured after merging, and the commit message understates the problem

The change does what it claims. The shortfall check still works and now costs nothing:

20:41:12  == A complete cycle through the orchestrator ==
20:57:17      AMWScan alone: 4   orchestrator: 3   accounted for: 1
20:57:17  ✓ the 1 AMWScan finding(s) the orchestrator did not take are accounted for
20:57:18  == Quarantine with real POSIX permissions ==

One second, where it previously launched a full scan.

But the whole run took 100m42s, and 0 failure(s). My commit message said this had gone "from roughly a quarter of an hour to nearly an hour" — with the fix in, it is well past an hour, so that framing was wrong in the direction that flatters the fix.

Where the time actually goes, from the timestamps of one run:

section elapsed
the main cycle 16 min
quarantine (its own full scan) 24 min
resource limits (its own full scan) 24 min
the evasion pair (two full scans) the rest

So a full scan in that container now costs 16–24 minutes. Earlier today one reported Duration: 7m52.945s. I am not claiming my changes caused that — this machine has been running containers back to back for hours, and I have no clean benchmark to separate load from cause. Saying which it is would be the same guess this session has been about not making.

What is solid: four full scans remain, each of them tens of minutes, and removing one of the six was worth doing but does not fix the shape of the problem.

The next lever, not taken here

The quarantine section and the resource-limit measurement each run their own full scan. The memory-peak measurement could plausibly wrap the quarantine one instead of adding a third, though they run under different observation_mode settings and that difference is the reason they are separate today. Worth doing deliberately, with a measurement on an idle machine, rather than at the end of a long session on a loaded one.

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