Skip to content

[KGEN] Cache interpreter pointer values and type layouts - #7428

Open
bodiam wants to merge 1 commit into
modular:mainfrom
bodiam:fix/comptime-array-access-6975
Open

bodiam wants to merge 1 commit into
modular:mainfrom
bodiam:fix/comptime-array-access-6975

Conversation

@bodiam

@bodiam bodiam commented Oct 30, 2026

Copy link
Copy Markdown

Compile-time Array indexing repeatedly interns temporary pointer attributes and recalculates struct field layouts. Add a bounded interpreter-local pointer-value cache and reuse type sizes/alignments for the interpreter's fixed target. Both caches clear on reset; pointee values and the existing memory-validity checks remain uncached.

Addresses #6975. Draft for author review. This branch is independent of the #7183 fix in #7427.

Performance report: full methodology, samples, and remaining limitations. The PR includes a reproducible benchmark driver.

Apple M2 Pro / macOS 26.5.1, source-built compilers against upstream 8ed65fc. Medians of three cold object builds, alternating baseline/fixed order, using the identical standard-library package:

Compile-time workload Before After Wall-time reduction
Array, 64 elements x 3000 passes 17.8670 s 14.6154 s 18.2%
SIMD control, 64 x 3000 1.8711 s 1.8432 s 1.5%
Array, 512 elements x 100 passes 5.5837 s 4.9522 s 11.3%

The 64-element Array case remains about 7.9x slower than the SIMD control. This reduces the reported overhead; further interpreter work is needed to close that gap, so this PR does not automatically close the issue.

Validation: 15 selected interpreter, memory-error, Array, Span, and pointer test targets passed, including ordinary/parametric execution, 32-bit casts, and compile-time alias/mutation coverage. The benchmark smoke run and mypy check passed. ./bazelw run //:format and C++ formatting checks passed.

Assisted-by: AI

Avoid repeated MLIR uniquing of temporary pointers with a bounded interpreter-local cache keyed by address and type. Reuse type sizes and alignments for struct field addressing and serialization on the interpreter fixed target. Clear both caches on reset while retaining all existing pointee memory checks.

Add compile-time alias/mutation coverage, a cold-compilation benchmark with a SIMD control, and a performance report. On Apple M2 Pro the 64-element reproducer falls from 17.867s to 14.615s (18.2%); a wider-array case improves 11.3%. The residual SIMD gap is documented.

Addresses modular#6975

Assisted-by: AI
Signed-off-by: Erik Pragt <[email protected]>
@github-actions github-actions Bot added mojo-stdlib Tag for issues related to standard library waiting-on-review labels Oct 30, 2026
@bodiam
bodiam marked this pull request as ready for review October 30, 2026 08:35
@bodiam
bodiam requested review from a team as code owners October 30, 2026 08:35
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-30T08:37:25.116616Z
We couldn’t complete this review. Comment @codex review to try again.
963f186 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

mojo-stdlib Tag for issues related to standard library waiting-on-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant