Skip to content

D-522 stage 1: shared FP-bridge bodies — jit_host_bridge −82% (binary −21%)#145

Merged
chaploud merged 2 commits into
mainfrom
develop/d522-fp-bridge-delegation
Jul 16, 2026
Merged

D-522 stage 1: shared FP-bridge bodies — jit_host_bridge −82% (binary −21%)#145
chaploud merged 2 commits into
mainfrom
develop/d522-fp-bridge-delegation

Conversation

@chaploud

Copy link
Copy Markdown
Contributor

Summary

Binary-size campaign (ADR-0204 D1) stage 1. t1fp/t2fp host-call thunks previously inlined the payload-lookup + marshalling + invokeCb body into every (kinds × ret × slot) instantiation (~300 B × 3,840 thunks). The bodies now live in noinline fpBridge1/fpBridge2, monomorphized per (kinds, ret) only — 60 shared bodies; each per-slot thunk reduces to arg forwarding (~23 B).

Measured (arm64)

Metric Before After
api.jit_host_bridge (ReleaseSafe) 1,311 KB / 5,453 syms 232 KB (−82%)
CLI binary (ReleaseSafe) 5,282,584 B 4,173,736 B (−21%)
ReleaseFast base / lean (size_history rows in this PR) 3,884,856 / 3,646,232 3,563,960 / 3,325,304

Safety

  • No ABI change: thunk C-ABI signatures (callconv(.c), param/return types) and the planted fn-ptr table shape untouched; all three trap paths (null payload base, arity mismatch, callback trap) preserved in the shared bodies.
  • Verified: zig build test + test-c-api-conformance (jit_callback / _args / _fp) green; independent Devil's-Advocate critique 20/20 PASS (READY TO SHIP).
  • Win64 positional FP-ABI coupling is exercised by CI's x86_64-windows leg (noted as the critique's unverified item).

Also in this PR

  • debt.yaml: D-522 stage-1 record; stage 2 (slot-axis collapse) re-scored to ~200 KB recoverable → demand-driven. D-521 root cause sharpened: dispatch() inline-for inlines all 409 registered handler bodies into emit.compile + O(n) dispatch — stage A = comptime fn-pointer table.
  • size_history.yaml: post-stage-1 rows.

chaploud added 2 commits July 16, 2026 12:38
t1fp/t2fp previously inlined the payload-lookup + marshalling + invokeCb
body into every (kinds x ret x slot) instantiation: ~300 B x 3,840
thunks. The bodies now live in noinline fpBridge1/fpBridge2,
monomorphized per (kinds, ret) only — 60 shared bodies; each per-slot
thunk is reduced to arg forwarding (~23 B).

Measured (ReleaseSafe arm64 CLI): api.jit_host_bridge 1,311 KB -> 232 KB
(-82%); whole binary 5,282,584 -> 4,173,736 B (-21%). No ABI change: the
thunk C-ABI signatures and the planted fn-ptr table shape are untouched.
Covered by test-c-api-conformance (jit_callback_fp / _args / jit_callback).
…e; size rows

- D-522: stage 1 DONE (jit_host_bridge 1,311 KB -> 232 KB ReleaseSafe;
  ReleaseFast base/lean each -321 KB, rows recorded). Stage 2 (slot-axis
  collapse) re-scored to ~200 KB recoverable vs JIT call-sequence risk ->
  demand-driven, re-score after D-521.
- D-521: root cause sharpened — dispatch_collector.dispatch() inline-for
  inlines all 409 registered arm64 handler bodies into emit.compile and
  dispatches via an O(n) compare chain. Stage A = comptime fn-pointer
  table (O(1), kills the inline duplication); stage B = migrate the
  remaining switch ops, delete the switch.
@chaploud
chaploud enabled auto-merge (squash) July 16, 2026 03:47
@chaploud
chaploud merged commit e2f65de into main Jul 16, 2026
5 checks passed
@chaploud
chaploud deleted the develop/d522-fp-bridge-delegation branch July 16, 2026 04:08
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