Skip to content

[codex] Cache monomorphic array guard feedback#5307

Merged
proggeramlug merged 1 commit into
codex/perry-numeric-array-direct-fastpathfrom
codex/perry-array-guard-cache-fastpath
Jun 18, 2026
Merged

[codex] Cache monomorphic array guard feedback#5307
proggeramlug merged 1 commit into
codex/perry-numeric-array-direct-fastpathfrom
codex/perry-array-guard-cache-fastpath

Conversation

@andrewtdiz

Copy link
Copy Markdown
Contributor

Summary

Adds a small lock-free, direct-mapped fast cache for monomorphic array typed-feedback guard sites. The cache is seeded by the existing slow guard_observe path and only fast-passes when the current array observation exactly matches the cached feedback key and the runtime contract guard is valid.

Slow paths still update the typed-feedback registry, failures, megamorphic state, observations, fallback counters, and trace metadata. Trace snapshots merge cache fast-pass counts back into observed_count, per-site guard passes, and by-guard totals.

This is stacked on #5302.

Benchmark Evidence

Baseline at ed71efde8585 from #5302:

  • Direct matrix runs: 1736ms, 1730ms, 1729ms, 1738ms, 1714ms; checksum always 41079519680
  • quick.sh matrix: 1745ms / 28MB
  • perf stat matrix: 28.04B instructions, 4.65B branches, 6.34B cycles
  • Typed-feedback trace: 33,619,968 numeric array get guard passes and 65,536 set guard passes with 0 get/set failures

After this change:

  • Direct matrix runs: 1239ms, 1258ms, 1223ms, 1247ms, 1226ms; checksum always 41079519680
  • quick.sh matrix: 1228ms / 30MB
  • perf stat matrix: 16.74B instructions, 3.09B branches, 4.49B cycles
  • Trace still reports 33,619,968 numeric array get guard passes and 65,536 set guard passes with 0 get/set failures

Measured impact:

  • Direct matrix median: 1730ms -> 1239ms, 28.4% faster
  • quick.sh matrix: 1745ms -> 1228ms, 29.6% faster
  • Matrix instructions: 28.04B -> 16.74B, 40.3% fewer
  • Matrix branches: 4.65B -> 3.09B, 33.6% fewer
  • compare.sh --quick --runs 3 --warn-only nested_loops median: 921ms -> 662ms, 28.1% faster

Verification

  • cargo fmt --check
  • git diff --check
  • cargo test -p perry-runtime typed_feedback
  • cargo test -p perry-codegen --test typed_feedback
  • cargo test -p perry-codegen --test typed_shape_descriptors
  • PERRY_BIN=target/release/perry python3 tests/test_typed_feedback_runtime_evidence.py
  • tests/test_benchmark_output_verifier.sh
  • cargo build --release
  • target/release/perry compile --no-cache benchmarks/suite/16_matrix_multiply.ts -o /tmp/perry-matrix-array-guard-cache-final --quiet
  • benchmarks/quick.sh
  • benchmarks/compare.sh --quick --runs 3 --warn-only --json-out /tmp/perry-array-guard-cache-final-ed71efde8.json

Note: benchmarks/baseline.json is stale for this Linux environment, so compare was run with --warn-only and the PR body uses the captured local #5302 baseline.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8109785b-88d0-4cc4-b12b-9b9412d43206

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/perry-array-guard-cache-fastpath

Comment @coderabbitai help to get the list of available commands and usage tips.

@andrewtdiz andrewtdiz force-pushed the codex/perry-array-guard-cache-fastpath branch from 8a0c6c1 to 6a01499 Compare June 17, 2026 05:44
@proggeramlug proggeramlug force-pushed the codex/perry-numeric-array-direct-fastpath branch from ed71efd to 452b8d8 Compare June 17, 2026 13:38
@proggeramlug proggeramlug force-pushed the codex/perry-array-guard-cache-fastpath branch from 6a01499 to 6b54bf6 Compare June 17, 2026 13:38
@proggeramlug proggeramlug force-pushed the codex/perry-numeric-array-direct-fastpath branch from 452b8d8 to f49be7c Compare June 17, 2026 13:47
@proggeramlug proggeramlug force-pushed the codex/perry-array-guard-cache-fastpath branch from 6b54bf6 to 0f46886 Compare June 17, 2026 13:47
@proggeramlug proggeramlug force-pushed the codex/perry-numeric-array-direct-fastpath branch from f49be7c to f1945a4 Compare June 17, 2026 13:58
@proggeramlug proggeramlug force-pushed the codex/perry-array-guard-cache-fastpath branch from 0f46886 to 3b00735 Compare June 17, 2026 13:58
@proggeramlug proggeramlug marked this pull request as ready for review June 18, 2026 05:41
@proggeramlug proggeramlug force-pushed the codex/perry-numeric-array-direct-fastpath branch from f1945a4 to 73d3794 Compare June 18, 2026 06:36
@proggeramlug proggeramlug force-pushed the codex/perry-array-guard-cache-fastpath branch from 3b00735 to 83aa967 Compare June 18, 2026 06:36
@proggeramlug proggeramlug reopened this Jun 18, 2026
@proggeramlug proggeramlug merged commit 3af96b7 into codex/perry-numeric-array-direct-fastpath Jun 18, 2026
3 checks passed
@proggeramlug proggeramlug deleted the codex/perry-array-guard-cache-fastpath branch June 18, 2026 17:54
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