Skip to content

Add typed_module_cache retention measurement instrument (cache_walk + CacheWalkReport) - #5888

Merged
briansrls merged 7 commits into
mainfrom
session/royal-dove-850
Jun 28, 2026
Merged

briansrls merged 7 commits into
mainfrom
session/royal-dove-850

Conversation

@gunbai-bot

@gunbai-bot gunbai-bot Bot commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds cache_walk diagnostic binary and CacheWalkReport / measure_caches() to MultiEntryIndex to measure typed_module_cache retention at full corpus scale. Motivated by the ~4 GiB floor peak: this instrument measures the 3-way split (retention-of-all-at-once vs replication vs genuine-distinct) across both source roots combined.

SCAFFOLD — dissolution trigger: func_env.sig Rc-sharing > 1.0× in corpus (the dedup PR, currently parked on variant-owner grounding).

Retention measurement results

Runs against --source-root src/v2 --source-root dsl with all 426 *_test.dag entries:

Run Entries Modules cached VmHWM
5 entries 5 164 270 MiB
All entries 426 981 4,170 MiB (4.17 GiB)

3-way split at saturation (981 modules, 4.17 GiB)

Retention-of-all-at-once (~96%) — dominant: all 981 typed module graphs held simultaneously (no eviction). The typed item subtrees (function bodies, expression trees) are genuinely distinct — eviction (Lever C) is the primary lever.

Replication via func_env.signatures (~4%, ~173 MiB) — secondary: 591,867 total / 591,867 distinct (1.0× sharing). Every Rc is a fresh allocation; each module re-allocates sigs from its entire transitive import closure rather than sharing the parent's Rc. Fix is the dedup PR (#5884, parked). Reference: TypeEnv.bindings already achieves 99.0× sharing (262,149 total / 2,648 distinct) — that's the target model.

Genuine-distinct (irreducible) — 15,583 distinct typed items, 2,648 distinct TypeEnv bindings (already maximally shared), 981 distinct parse module nodes.

intern_table receipt — NOT a #5867 regression

distinct Rc<InternTable>: 4 at 5 entries (0.80/entry), 416 at 426 entries (0.977/entry) — ~1:1 per entry.

Mechanism: when a resolve_entry_with_index call interns new types, Rc::make_mut() sees strong-count > 1 (prior cached modules still hold their Rc to the existing table) and clones — leaving those modules frozen on Rc(N-1) while the new entry's modules get Rc(N). Within a single resolve_entry_with_index call: all modules share exactly 1 intern_table throughout. This is what #5867 fixed, and it still holds.

Conclusion: the 416 is cross-entry accumulation across a 426-entry single-process run. The floor's separate-process-per-shard model is NOT affected — each shard process resolves its entries independently and does not exhibit cross-entry sharing degradation. #5867 regression = NO.

How to run

# Build
CTRL_BUILD_BYPASS_SHIMS=1 cargo build --release -p v1-compiler --bin cache_walk

# Single heavy entry
target/release/cache_walk \
  --source-root src/v2 --source-root dsl \
  --entry src/v2/compiler/06_translate.dag

# Full saturation (all test entries)
# Add --entry for each *_test.dag under src/v2 and dsl, plus dsl/test/**/*.dag

VmHWM measurement: pipe through a /proc/$PID/status poller (no /usr/bin/time -v on runners); CTRL_BUILD_BYPASS_SHIMS=1 bypasses the ctrl-build shim for local builds.

Fixed-seed emit diff harness (for #5884 reference)

To verify #5884 is a no-op on emit output (requires grounding lane to land first):

# Baseline and fix must both sort map_keys identically (same v1_rt sort patch applied)
gunbc emit --source-root dsl --entry dsl/std/types.dag --seed 42 > baseline.rs
# apply #5884, rebuild, then:
gunbc emit --source-root dsl --entry dsl/std/types.dag --seed 42 > fix.rs
diff baseline.rs fix.rs  # expect empty

The 24-file non-empty diff on the current #5884 is scope-driven (variant owner chosen by import order, not field type) — not a no-op until the variant-owner-by-expected-type grounding lane lands (stern-moth).

3 discriminating sites (right-vs-wrong per direction):

  • dsl/std/types.dag — baseline picks BoolFalse as owner via import scope; fix picks BoolTrue via field-type; structural diff in emitted enum
  • dsl/std/integer.dag — baseline uses one ordering, fix another for IntVariant owners; both compile but emit different variant-ownership ordering
  • dsl/extdeps/os/os.dag — baseline / fix swap Present/Absent variant ownership; semantically equivalent but different emitted Rust

Test plan

  • cargo fmt --all — clean (verified locally after each push)
  • cargo clippy --all-targets -- -D warnings — passes in CI
  • cargo nextest run — passes in CI
  • No .dag files touched; no substrate changes

@gunbai-bot
gunbai-bot Bot marked this pull request as ready for review June 28, 2026 02:24
@gunbai-bot gunbai-bot Bot changed the title func_env.sigs single-authority dedup (resolve mem) Add typed_module_cache retention measurement instrument (cache_walk + CacheWalkReport) Jun 28, 2026
briansrls and others added 4 commits June 28, 2026 02:29
Both are diagnostic-only; dissolution trigger is func_env.sig Rc-sharing
rising above 1.0× in corpus (the dedup PR, currently parked).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@briansrls
briansrls merged commit c703725 into main Jun 28, 2026
2 checks passed
@briansrls
briansrls deleted the session/royal-dove-850 branch June 28, 2026 18:21
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