Skip to content

jit(wasm): size CA callee frames with per-token compact geometry#505

Closed
youknowone wants to merge 4 commits into
wasm-jitfrom
wasm-frame-geometry
Closed

jit(wasm): size CA callee frames with per-token compact geometry#505
youknowone wants to merge 4 commits into
wasm-jitfrom
wasm-frame-geometry

Conversation

@youknowone

Copy link
Copy Markdown
Owner

Summary

Stacked on #501. Removes the fixed MIN_FRAME_BYTES (2152B) layout floor for CA-allocated callee jitframes: each token freezes a compact FrameGeometry at its first compile (value region sized from the token's actual slot needs, then call area, dispatch key, and Ref homes at per-token offsets), matching how native jitframes are sized by the regalloc's actual frame depth (jitframe.py JITFRAME_FIXED_SIZE + frame_depth).

  • Arena execute_token frames keep the fixed floor (they are shared across tokens).
  • Chained bridges reuse the allocating token's frozen geometry; compile_bridge declines a bridge whose slot needs exceed it (safe fallback, no miscompile).
  • Host-side frame readers and per-bridge gcmap building take the token geometry instead of the global constants.

Motivation / measurements (fib32 via CALL_ASSEMBLER, interleaved ×5)

#501 moved CA callee frames from a malloc+LIFO pool to nursery GC allocation, which regressed fib32 0.83s → 1.20s purely from minor-GC frequency (gc_minors 262 → 5034): every CA call allocated a ~2.3KB fixed-layout frame. A 32MB-nursery probe (0.77s, minors 629) confirmed the cost is per-minor overhead × count; native dynasm shows only 146 minors with its frame-depth-sized frames.

With compact geometry:

wall (×5) gc_minors gc_majors
pooled malloc (pre-#501) 0.83–0.87s 262 0
#501 nursery, fixed layout 1.18–1.24s 5034 4
this PR 0.66–0.69s 1243 0

Output stays 2178309/exit 0. Synthetic suite 151/151 on wasm, dynasm, cranelift; i64env and majit-backend-wasm tests green.

🤖 Generated with Claude Code

…shots

Remove state_field_identity_const and the identity_const parameter chain:
build_vable_snapshot_boxes now always emits the identity as
SnapshotTagged::Box. The identity is a live input box; rewriting it to
TAGCONST excluded it from liveboxes/failarg numbering, baking a
trace-time object address into resume data. next_ref() now decodes the
identity from the failing frame's failarg slot (resume.py:1566-1578).

Assisted-by: Claude
…e pointer after collecting calls

wasm_jit_ca_alloc_frame switches from the malloc+LIFO pool to a
collecting nursery allocation (rewrite.py gen_malloc_nursery_varsize_frame),
retiring the CA_FRAMES pool. Because a minor collection can now move the
running frame and the collector cannot update wasm locals, trace bodies
reload local 0 from the jitframe shadow-stack top before every
post-collection home reload (_reload_frame_if_necessary, assembler.py:1369),
and the CA arm reloads the caller frame via the new jf_under_top_ptr()
accessor after its callee push. Trampoline fallback paths keep the
documented non-moving-frame assumption.

fib32 via CA: gc_majors 262 (oldgen variant) -> 4. Synthetic suite
151/151 on wasm, dynasm, cranelift.

Assisted-by: Claude
Replace the fixed MIN_FRAME_BYTES frame layout for CA-allocated callee
frames with a per-token FrameGeometry frozen at the token's first
compile: value region sized from the token's actual slot needs, then
call area, dispatch key, and Ref homes at per-token offsets
(jitframe.py sizes frames by the regalloc frame_depth). Arena
execute_token frames keep the fixed floor. compile_bridge declines a
chained bridge whose slot needs exceed the frozen geometry. Host-side
frame readers and per-bridge gcmap building take the token geometry
instead of the global constants.

fib32 via CA: gc_minors 5034 -> 1243, wall 1.20s -> 0.66-0.69s
(malloc-pool baseline 0.83s). Synthetic suite 151/151 on wasm, dynasm,
cranelift.

Assisted-by: Claude
@coderabbitai

coderabbitai Bot commented Jul 12, 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7c194038-9395-434c-b7d4-3616a0628b00

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 wasm-frame-geometry

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@youknowone youknowone closed this Jul 12, 2026
@youknowone youknowone deleted the wasm-frame-geometry branch July 12, 2026 12:26
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