Skip to content

fix(builder): check each builder once per up_to_date call - #429

Merged
lachlangrose merged 1 commit into
masterfrom
fix/up-to-date-visit-once
Nov 26, 2026
Merged

lachlangrose merged 1 commit into
masterfrom
fix/up-to-date-visit-once

Conversation

@lachlangrose

Copy link
Copy Markdown
Member

Problem

Every evaluation starts with builder.up_to_date(). BaseBuilder.up_to_date recursed into the builder of every fault of the feature, and FaultBuilder.up_to_date into its three coordinate builders, each of which recursed into the faults that cut the frame — with no memory of what was already checked. One check therefore walked every path through the graph of faults (×3 at each fault frame).

In a network of cutting faults this dominated the build: building one fault of a 94-fault test model (14 faults in its chain of cutting faults) made 36 million up_to_date calls (and as many logger.info calls) for 652 fault applications, 45 of the 51 s.

Fix

The outermost up_to_date call keeps the set of builders it has checked (in a context variable, so nested calls share it and threads do not), and a builder already in the set returns at once. The recursion still brings the faults of a builder up to date before the builder itself, so a skipped builder is already up to date. The fault and frame builders only delegate to their coordinate builders, so they need no change; no signature changes.

Results

Tests

  • tests/unit/modelling/test_builder_up_to_date_once.py: in a small graph of cutting faults each interpolator is checked once per call (up to 16 times before the fix); a fault marked stale is still rebuilt.
  • Full pytest tests: 2913 passed, 31 skipped. Ruff: no new findings.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XADRvHhG72666JkYNHtzUx

A feature depends on the builders of its faults, and a fault frame on the
builders of the faults that cut it. BaseBuilder.up_to_date recursed into
every fault builder, and each fault frame into its three coordinate
builders, with no memory of what was already checked, so one check walked
every path through that graph (x3 at each fault frame). It runs at the
start of every evaluation. In a network of cutting faults this dominated:
building one fault of a 94-fault model made 36 million up_to_date calls
(and as many logger.info calls) for 652 fault applications.

The outermost call now keeps the set of builders it has checked (in a
context variable), and a builder already in it returns at once. The
recursion still brings the faults up to date before the builder itself,
so a skipped builder is already up to date.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XADRvHhG72666JkYNHtzUx
@lachlangrose
lachlangrose merged commit db5e65a into master Nov 26, 2026
37 checks passed
@lachlangrose
lachlangrose deleted the fix/up-to-date-visit-once branch November 26, 2026 23:04
lachlangrose added a commit that referenced this pull request Nov 26, 2026
…o feat/003-fault-evaluation-performance

The branch already had the same fixes as merges of their PR branches.
Two conflicts: _fault_segment.py keeps the branch's placement of the #425
fallback (after the frame gradient of _evaluate_frame), and
test_cut_fault_step_direction.py keeps the branch's version that turns
the shared frame lookup off for the NaN-rule test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XADRvHhG72666JkYNHtzUx
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