Skip to content

R1d: faster cold catalog preparation, compilation stays in preparation - #1225

Merged
trissim merged 6 commits into
mainfrom
refactor/R1d-catalog-prepare-cold-start
Oct 12, 2026
Merged

trissim merged 6 commits into
mainfrom
refactor/R1d-catalog-prepare-cold-start

Conversation

@trissim

@trissim trissim commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Replaces closed #1222 (R1c). Owner decision: every Numba kernel is compiled in catalog preparation and its forked cache children, never at first use. This PR makes cold preparation faster while it still compiles the whole catalog before readiness. Receipt: docs/refactor/consolidation-20261009/R1d-catalog-prepare-cold-start.md.

What was wrong (measured on main, Linux, 6 cores / 12 threads)

  • No cache child forked unless NUMBA_CACHE_DIR was set, which only the desktop launcher and benchmark harnesses do. CI jobs and plain server starts compiled all 665 kernel signatures on one CPU (94.5 s here; the 222 s on macos-15-intel). Numba was persisting its cache beside the sources all along.
  • Discovery 18.6 s: three skimage behaviour probes took 9.6 s (rolling_ball, denoise_nl_means, hough_ellipse), and installed requirement metadata was re-parsed 619 times.
  • After the children, the server compiled 86 more kernel signatures serially (9.5 s): 26 @processing_prepare hooks and two families that never declared persistent kernel work.

Changes

  • Cache children fork wherever Numba persists (the NUMBA_CACHE_DIR requirement is removed).
  • _openhcs_requirements parsed once per process (the only piece taken from R1c); module sources parsed to AST once.
  • Behaviour probe arrays 3x8x8 / 8x8 instead of 3x20x20 / 20x20. All 164 skimage functions classify identically at edges 20, 16, 12, 10, 8, 6, 4.
  • Declared hooks run in cache children after the registry children, one child per CPU; EdgeEnhancementStrategy and ImagePayloadUint8Strategy declare persistent kernel work.
  • The server compiles 0 kernels itself on a cold start; a second start compiles 0 anywhere.

Before / after

Cold preparation, 12 threads, NUMBA_CACHE_DIR set main branch
import 0.9 s 0.6 s
discovery 18.6 s 7.8 s
kernel cache children 23.1 s (31) 27.7 s (45)
kernels compiled by the server, serial 9.5 s 1.3 s (0 compilations)
signatures, configuration 0.8 s 0.5 s
total 52.9 s 37.9 s
Other cases main branch
NUMBA_CACHE_DIR unset 103.6 s with this branch's discovery fixes and the old rule (0 children) 37.6 s
4 physical cores 60.4 s 49.5 s
second start, warm 9.8 s 7.7 s
run-well-throughput ExampleHuman, whole command main first main second branch first branch second
1 worker, 1 well 64.7 s 22.1 s 46.6 s 19.0 s
4 workers, 4 wells 69.4 s 22.4 s 50.7 s 20.0 s

Not done

  • No CI Numba cache: Numba validates entries by source (mtime, size) and path, and server jobs install fresh wheels, so restored entries would be stale (details in the receipt).
  • Shared kernels are still compiled by several children at once (56.5 of 195 compile seconds); expected wall gain under 2 s.
  • Intel macOS not re-measured; no debug workflow.

Gates

  • verify_branch.sh: 38 failed, 11640 passed, 25 skipped, 2 errors in 642.63s; collected 11702, reported 11679, crash lines 0; new vs known: 3; only on r1dcold: (empty: the three also fail on main when rerun).
  • smoke_local.sh: smoke pytest exit 0 (64 s): 7 passed; smoke gui exit 0 (19 s); smoke rc=0.
  • official30 parity, under flock, from an empty Numba cache: 1 passed, 2 warnings in 697.94s; 30 cases in summary.csv.
  • guardrails_local.sh: guardrails rc=1. ratchet openhcs|scripts|benchmark exit 1 and nra-r1 exit 1: both pinned tools crash while importing themselves (_FamilyMeta._register_class() got an unexpected keyword argument 'replaces' in agent-comms; DuplicateRegistryKeyError in NominalRefactorAdvisor), before reading the diff. Not checked whether main fails the same way. Draft until that is settled.

R1d · guards 3/3 · production −30 +111 · tests −2 +65 (adds a scheduling stage for hooks)

🤖 Generated with Claude Code

trissim and others added 6 commits October 12, 2026 08:35
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…two families in cache children

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ne child per CPU; guards

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@trissim
trissim marked this pull request as ready for review October 12, 2026 15:27
Copilot AI balanced review requested due to automatic review settings October 12, 2026 15:27
@trissim
trissim merged commit 2582bbd into main Oct 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

2 participants