8000 perf(check): run OutputTypesValid on the blocking pool by bryan-minimal · Pull Request #4004 · gominimal/minimal · GitHub
[go: up one dir, main page]

Skip to content

perf(check): run OutputTypesValid on the blocking pool - #4004

Open
bryan-minimal wants to merge 1 commit into
mainfrom
perf/check-otv-offload
Open

bryan-minimal wants to merge 1 commit into
mainfrom
perf/check-otv-offload

Conversation

@bryan-minimal
@bryan-minimal bryan-minimal commented Dec 3, 2026 •
Copy link
Copy Markdown
Member

Why

On prod (2026-12-03, minimal 16cc8a9, the first sweep after a res-server boot, pkgs#1837), the checks phase took 310 s. Polling-thread time was 568 s across 1155 check_package spans, and checker_top=OutputTypesValid accounted for 483 s of it (85%), e.g. checkers="OutputTypesValid=47/47,...". OutputTypesValid ran its glob walk and opened and ELF-parsed each matched file inline, inside one poll of the thread that drives the whole check stream. Cold, that is about 0.43 ms per output file, and the walk blocked every in-flight package's checkers while it ran. MissingRuntimeDeps and OutputsFreeOfDetbuild already run on the blocking pool.

What

  • crates/check/src/outputs.rs: OutputTypesValid follows the OutputsFreeOfDetbuild/DetbuildScan pattern. Under the graph guard it copies what the walk needs into a new OutputTypesScan: the outputs in declaration order, the target arch, the spec hash, the cache, the check cache and the cancel token. It then drops the guard and runs OutputTypesScan::verdict through poll_timing::spawn_blocking with the check_package span entered. The walk body is unchanged apart from where it reads its inputs, so verdicts, messages and their order stay the same. It now checks for cancellation per file, as MissingRuntimeDeps does, since a blocking task can't be interrupted.
  • Its time now appears in the span's offloaded field (OutputTypesValid=wall/cpu) instead of checkers.
  • New test output_types_valid_fails_a_malformed_binary_off_the_polling_thread: a non-ELF, non-script binary output fails and the error names the file, a script beside it passes, and a measured check (poll_timed(true, ..)) counts the walk as offloaded work.
  • Doc comments in lib.rs and poll_timing.rs now list OutputTypesValid among the offloaded checkers.

Prior attempts

gh pr list --search for OutputTypesValid, offload and spawn_blocking, and git log -S/--grep on crates/check, found no earlier attempt to offload OutputTypesValid and no revert of an offloaded checker.

Expected effect

On a cold sweep, the per-file I/O moves off the single polling thread and runs in parallel on up to 20 permits. The checks phase should drop toward the warm level, and checker_top should stop being OutputTypesValid.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Package output validation now correctly rejects malformed binary files while continuing to accept executable scripts with a shebang.
  • Performance
    • Output checks run without holding the package graph read lock, helping keep other work responsive during validation.
    • Checks now respond to cancellation before reading cached build data and while processing files.

OutputTypesValid walked every output glob and opened and ELF-parsed each
matched file inside one poll of the thread that drives the check stream.
Cold, that is about 0.43 ms per output file, and on prod (2026-12-03,
pkgs#1837, first sweep after boot) OutputTypesValid was checker_top for
483 s of the 568 s of polling-thread time in a 310 s checks phase.

Like OutputsFreeOfDetbuild, copy what the walk needs (outputs in
declaration order, target arch, spec hash, caches, cancel token) under the
graph guard, drop the guard, and run the walk through
poll_timing::spawn_blocking with the check_package span entered. Verdicts,
messages and their order are unchanged; the time now shows under the
span's offloaded field instead of checkers. The walk checks for
cancellation per file, as MissingRuntimeDeps does.

Adds a test that a malformed binary output fails, names the file, and
that a measured check counts the walk as offloaded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bryan-minimal
bryan-minimal requested a review from a team as a code owner December 3, 2026 23:26
@coderabbitai
coderabbitai Bot commented Dec 3, 2026 •
Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

OutputTypesValid now runs output validation on the blocking pool after copying scan inputs and releasing the graph read guard. The scan checks cancellation and retains the existing validation logic. A test checks malformed binary and shebang outputs and verifies timing records offloaded work.

Changes: Output validation

Layer / File(s) Summary
Blocking output scan
crates/check/src/outputs.rs, crates/check/src/lib.rs, crates/check/src/poll_timing.rs
OutputTypesValid copies scan inputs, releases the graph read guard, and runs the scan on the blocking pool. The scan checks cancellation and retains the existing output checks. A new test checks malformed binary and shebang outputs and verifies offloaded timing. Comments and examples identify OutputTypesValid as offloaded work.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant OutputTypesValid
  participant GraphReadGuard
  participant SpawnBlocking as poll_timing::spawn_blocking
  participant OutputTypesScan
  participant CachedBuildData
  OutputTypesValid->>GraphReadGuard: Copy outputs and graph-derived metadata
  OutputTypesValid->>GraphReadGuard: Release read guard
  OutputTypesValid->>SpawnBlocking: Submit output scan
  SpawnBlocking->>OutputTypesScan: Run scan
  OutputTypesScan->>CachedBuildData: Read cached build data
  OutputTypesScan-->>SpawnBlocking: Return verdict and errors
  SpawnBlocking-->>OutputTypesValid: Return scan result
Loading

Possibly related PRs

  • gominimal/minimal#3906: Adds the blocking-pool timing fields and checker classification used by this change.

Suggested reviewers: norrietaylor, minimal-foundry

Merge Risk: Minimal · up to 2a619

This change moves output-type validation off the polling thread so cold file reads no longer stall it. Verdicts and messages are intended to stay the same, and a new test covers a malformed binary and a passing script. No actionable merge-blocking risk is evident.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Description check Inconclusive The description covers the required template areas. The Summary is detailed and explains the why and what, with production context and the expected effect. The Testing section is missing: it names a n… Add a Testing section that lists the commands run (for example cargo test for output_types_valid_fails_a_malformed_binary_off_the_polling_thread and cargo clippy) and pastes the relevant output. Link related issues with Refs or Closes if an…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title "perf(check): run OutputTypesValid on the blocking pool" follows the Conventional Commit form and names the main change. The PR moves OutputTypesValid's glob walk and file parsing from the p…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "perf(check): run OutputTypesValid on the blocking pool" follows the Conventional Commit form and names the main change. The PR moves OutputTypesValid's glob walk and file parsing from the polling thread to the blocking pool via poll_timing::spawn_blocking, which the title describes.

Full details: Description check

Explanation

The description covers the required template areas. The Summary is detailed and explains the why and what, with production context and the expected effect. The Testing section is missing: it names a new test but does not list commands run (for example cargo test or cargo clippy) or paste output as evidence. The Checklist is absent. The Summary also has no issue link (Refs or Closes), and the Checklist items are not ticked. The description has no note on the breaking-change footer, which may not apply.

Resolution

Add a Testing section that lists the commands run (for example cargo test for output_types_valid_fails_a_malformed_binary_off_the_polling_thread and cargo clippy) and pastes the relevant output. Link related issues with Refs or Closes if any exist. Complete the Checklist: confirm docs were updated if behavior changed (the doc comments in lib.rs and poll_timing.rs changed), and state whether a BREAKING CHANGE footer is needed.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks the output trail,
Then sends the scan to work off-rail.
The graph guard drops; the checks proceed,
A malformed file gets marked with speed.
A script with shebang passes through,
And timing notes the work it knew.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 5861cd40-2483-42e6-a87f-b0cd5f060367
Commits

Reviewing files that changed from the base of the PR and between 472a6a7 and 2a619db.

Files selected for processing: 3

  • crates/check/src/lib.rs
  • crates/check/src/outputs.rs
  • crates/check/src/poll_timing.rs

Included review availability: This review used your included allowance. Your plan provides up to 5 included reviews per hour; 1 remain after this review.

@minimal-foundry
minimal-foundry Bot commented Dec 3, 2026 •
Copy link
Copy Markdown
Contributor

Approved: no findings at 2a619dbbedc8.

Nothing to do.

Clobber: none seen.

@minimal-foundry minimal-foundry Bot left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minimal-review — advisory review

Verdict COMMENT — No findings.

Panel: 2 of 3 personas ran (correctness, security); did not complete: supply-chain.

@minimal-foundry minimal-foundry Bot added the review:approved minimal-review approved the current head label Dec 3, 2026
@norrietaylor norrietaylor left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving OutputTypesValid's glob walk and ELF parsing onto poll_timing::spawn_blocking follows the OutputsFreeOfDetbuild/DetbuildScan pattern correctly. The scan copies the outputs, arch, spec hash and caches under the guard and drops the guard before the walk. The verdicts and messages are unchanged. Errors are stringified exactly as check_package_measured already does, and ctx.bail_if_cancelled() there still returns Error::Cancelled after the join. The offloaded timing is attributed through the OFFLOADED task-local that poll_timed sets, and the new test checks it. CI is green. One medium finding: the per-file cancellation added to the walk has no test (inline).


Generated by Claude Code

.match_files_for_glob(cached_build.path(), glob)?
.iter()
{
crate::bail_if_cancelled(&self.cancel)?;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: the cancellation points this PR adds to OutputTypesValid (here, and before cache.read_dir at line 94) are new behaviour that no test exercises. Before this change the walk had no cancellation point; now a token that fires mid-walk makes OutputTypesScan::verdict return Err(Error::Cancelled) instead of finishing. The existing run_checks_bails_on_cancelled_token test (lib.rs) cancels before any checker runs, so it is stopped at the semaphore select! in package_check_futures and never reaches this code. The new output_types_valid_fails_a_malformed_binary_off_the_polling_thread test never cancels. If a later edit drops this check, or moves it so that a cancelled walk returns Ok(result) with a Pass verdict after reading only some files, nothing fails.

Suggested fix: add a test modelled on no_detbuild_a_cancelled_read_is_never_clean. Build an OutputTypesScan directly over a staged build, cancel its token, call verdict, and assert matches!(r, Err(Error::Cancelled)), never Ok(..) with a Pass verdict.


Generated by Claude Code

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review:approved minimal-review approved the current head

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0