Skip to content

Cache const-eval local layouts per instance - #161481

Closed
anonrig wants to merge 2 commits into
rust-lang:mainfrom
anonrig:consteval-cache-instance-local-layouts
Closed

Cache const-eval local layouts per instance#161481
anonrig wants to merge 2 commits into
rust-lang:mainfrom
anonrig:consteval-cache-instance-local-layouts

Conversation

@anonrig

@anonrig anonrig commented Aug 21, 2026

Copy link
Copy Markdown

Repeated calls to the same monomorphic const fn currently re-compute the layout of every local on each invocation: LocalState::layout is a per-frame cell and starts empty when the frame is pushed.

This adds a per-interpreter cache keyed by instance and optional promoted index. The first call fills it; later calls prefill the frame cells and skip instantiate + layout_of.

This is the remaining miss after the per-interpreter type layout cache (#157275). Large const tables that call small helpers (f64::from_bits, outlined math) currently hit layout_of_local once per call instead of once per instance — see #157010 (image, moxcms/pxfm).

Local same-commit stage1 measurements (--edition=2024 --crate-type=bin --emit=metadata, median of 3 after warmup):

workload before after
outlined update_sum table, N=2^16 0.424s 0.412s
outlined update_sum table, N=2^18 1.604s 1.548s
f64::from_bits helper × 3 × 2^17 4.739s 4.426s

The leftover outlined-vs-inlined gap is interpreter call overhead, not layout. The cache removes the redundant layout_of_local work described in #157010.

Not stacked on #161477. Different subsystem (CTFE layouts, not next-solver fulfillment).

r? RalfJung

Repeated calls to the same monomorphic const fn re-computed each local's
layout because the per-frame cell starts empty. Cache layouts by
(Instance, Option<Promoted>) so later invocations skip instantiate and
layout_of.
@rustbot

rustbot commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 21, 2026
@rustbot

rustbot commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

RalfJung is not on the review rotation at the moment.
They may take a while to respond.

@rustbot

rustbot commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @RalfJung (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

Cell::set does not need a mutable locals binding, and rustc treats
warnings as errors in this crate.
@RalfJung

Copy link
Copy Markdown
Member

Not stacked on #161477. Different subsystem (CTFE layouts, not next-solver fulfillment).

What does this have to do with anything? This comment makes no sense.

Please read our LLM policy and let me know if and how LLMs were used in generating any part of this PR.

@anonrig

anonrig commented Aug 21, 2026

Copy link
Copy Markdown
Author

Updating pr description. Sorry for the confusion!

@anonrig anonrig closed this Aug 21, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants