Skip to content

feat(jit): specialize Set/ArrayPush on delayed-move collection rebinds - #1

Merged
fffonion merged 1 commit into
masterfrom
perf/jit-collection-mutation
Jul 15, 2026
Merged

feat(jit): specialize Set/ArrayPush on delayed-move collection rebinds#1
fffonion merged 1 commit into
masterfrom
perf/jit-collection-mutation

Conversation

@fffonion

Copy link
Copy Markdown
Collaborator

Record same-local rebinds (stloc Null then Set/ArrayPush) directly in native traces, removing the call boundary that previously forced interpreter fallback.

Key changes:

  • ValueInfo now carries a source_local provenance tag set exclusively at Ldloc; arithmetic, constants, and call outputs clear it, ensuring the recorder and static loop-header plan agree on which local a value came from.
  • Recorder selects ArraySet / MapSet / ArrayPush specialization only when the container operand still carries the source local and that symbolic local is Null (dirty + known_type Null). Additional args that also share the moved local are rejected to prevent alias correctness issues.
  • New native bridge helpers pd_vm_native_collection_set and pd_vm_native_array_push use ptr::replace to take true ownership of the container slot, perform COW/rebind/shared-impl logic, and write the result back to the same owned-temp slot, compatible with native loop-back.
  • Reusable owned helpers builtin_set_owned / builtin_array_push_owned keep interpreter and JIT paths on the same semantics.
  • Lowering allocates MutationArgBox temp slots for index/key/value and calls collection_set / array_push native helpers with status checking.
  • Benchmark harness extended to gate per-sample native execution growth and freeze trace_attempts / recorded_traces / native traces during measurement.

Tests (all passing):

  • trace_jit_specializes_same_local_array_set_through_loop_back
  • trace_jit_specializes_same_local_map_set_through_loop_back (dual mutation with null-delete)
  • trace_jit_specializes_same_local_array_push_through_loop_back
  • trace_jit_array_set_preserves_cow_alias
  • trace_jit_does_not_consume_non_moved_array_set_container

Collection rebind benchmark (release, 50K iters, width=256, 15 samples):
array: interpreter 5928 µs → JIT 1181 µs (0.20×, ~5× speedup)
map: interpreter 22822 µs → JIT 2325 µs (0.10×, ~10× speedup)

WAF benchmark sub-par because its Set calls do not use the rebind pattern; JIT trace statistics confirm the expected LoopBack shape for the micro-bench workloads.

Record same-local rebinds (stloc Null then Set/ArrayPush) directly in native
traces, removing the call boundary that previously forced interpreter fallback.

Key changes:
- ValueInfo now carries a source_local provenance tag set exclusively at
  Ldloc; arithmetic, constants, and call outputs clear it, ensuring the
  recorder and static loop-header plan agree on which local a value came
  from.
- Recorder selects ArraySet / MapSet / ArrayPush specialization only when
  the container operand still carries the source local and that symbolic
  local is Null (dirty + known_type Null). Additional args that also share
  the moved local are rejected to prevent alias correctness issues.
- New native bridge helpers pd_vm_native_collection_set and
  pd_vm_native_array_push use ptr::replace to take true ownership of the
  container slot, perform COW/rebind/shared-impl logic, and write the
  result back to the same owned-temp slot, compatible with native
  loop-back.
- Reusable owned helpers builtin_set_owned / builtin_array_push_owned keep
  interpreter and JIT paths on the same semantics.
- Lowering allocates MutationArgBox temp slots for index/key/value and
  calls collection_set / array_push native helpers with status checking.
- Benchmark harness extended to gate per-sample native execution growth
  and freeze trace_attempts / recorded_traces / native traces during
  measurement.

Tests (all passing):
- trace_jit_specializes_same_local_array_set_through_loop_back
- trace_jit_specializes_same_local_map_set_through_loop_back (dual
  mutation with null-delete)
- trace_jit_specializes_same_local_array_push_through_loop_back
- trace_jit_array_set_preserves_cow_alias
- trace_jit_does_not_consume_non_moved_array_set_container

Collection rebind benchmark (release, 50K iters, width=256, 15 samples):
  array:  interpreter 5928 µs  →  JIT 1181 µs  (0.20×, ~5× speedup)
  map:    interpreter 22822 µs →  JIT 2325 µs  (0.10×, ~10× speedup)

WAF benchmark sub-par because its Set calls do not use the rebind pattern;
JIT trace statistics confirm the expected LoopBack shape for the micro-bench
workloads.
@fffonion
fffonion merged commit 73fb787 into master Jul 15, 2026
12 checks passed
@fffonion
fffonion deleted the perf/jit-collection-mutation branch July 15, 2026 19:51
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