ReviewOS

zig-utils/zig-js

Optimizer: add call inlining, escape analysis, and scalar replacement

#468
Open chris opened this 9 days ago ·
9 days ago

Parent: #459 Depends on: #467, #471

Goal

Add sound JavaScript call specialization, inlining, escape analysis, and scalar replacement so hot application call graphs and short-lived allocations do not pay canonical runtime cost.

Current boundary

Optimizer call links can jump directly to a current callee artifact, but bodies are not inlined and short-lived closures/objects/arrays/arguments remain material allocations.

Scope

  • Build monomorphic and bounded-polymorphic call-site profiles with versioned callee/shape/realm assumptions.
  • Inline ordinary, method, constructor, closure, and small builtin bodies with exact this, new.target, arguments/rest, exceptions, tail calls, and debugger-visible frames.
  • Perform interprocedural effect summaries, escape analysis, scalar replacement, allocation sinking, and closure/environment stack allocation where identity cannot escape.
  • Materialize eliminated objects/environments/arguments exactly on deopt, debugger inspection, exception escape, weak observation, or host boundary.
  • Budget code growth and compilation latency; retain non-inlined direct-call links when inlining is not profitable.

No-workaround rules

  • Do not assume a function/property remains unchanged without a guarded version; do not erase observable allocation identity, WeakRef/finalizer behavior, prototype/accessor calls, stack traces, or OOM timing where specified.
  • No hardcoded benchmark callees or always-inline policy.

Acceptance

  • Forced-on/off differentials cover polymorphism, rebinding, recursion, construct/new.target, exceptions/finally, eval, debugger stacks, GC/WeakRef/finalization, and no-GIL invalidation.
  • Deopt materialization is failure-safe and precisely rooted.
  • Profiles prove fewer runtime call entries and allocations on call/closure/application rows.
  • Compilation time and executable-byte budgets are measured and bounded.
  • Every retained speedup passes exact-parent wall/CPU/RSS evidence with no #44 regression.

Foundation

Direct call links and epoch retirement landed under #433/#439; current call-link contract is documented in docs/optimizing-jit.md.

9 days ago

Dependency #471 is now complete and closed with exact-parent invalidation evidence in 5e0c4023. The precise artifact/call-link lifetime foundation is therefore available for guarded call-site specialization; this issue remains dependent on #467 and none of its inlining/materialization acceptance boxes are being claimed yet.

9 days ago

Closed #1086 in 102da458: captured and receiver arithmetic inputs could re-enter JavaScript through coercion after a native caller activation had been elided. Both executed warmed failures now preserve active caller arguments and callback identity/order. Mutable input snapshots are not a no-reentry proof; safe argument-only numeric entries retain actual native hits.

Forced tree/VM JIT off/on, explicit optimizer entry/miss, mapped parameters, exceptions, real-GC, and four no-GIL workers pass Debug, ReleaseSafe, and unsuppressed TSan. The 2,093 affected upstream outcomes are unchanged; 700 seeded fuzz programs and the broader JIT/VM/concurrency gates pass. Full hosted integration is pending. This soundness prerequisite does not complete general inlining, scalar replacement, or performance acceptance.

Sign in to comment on this issue.