Skip to content

perf(jit): serve array.slice as a callout - #316

Merged
siyul-park merged 2 commits into
mainfrom
perf/jit-slice-callout
Nov 10, 2026
Merged

siyul-park merged 2 commits into
mainfrom
perf/jit-slice-callout

Conversation

@siyul-park

Copy link
Copy Markdown
Owner

Summary

Part C1 of the string/allocation review. pprof of fannkuch jit: engine.settle 47.6%, of which engine.bridge 27.8%, because ARRAY_SLICE has no lowering and bridges 720 times per Run. The op only allocates a copy, which is the class the callout path serves without a scratch frame, operand retains, or a handler run.

  • One implementation. Interpreter.slice(array, start, end) holds the semantics (type check, host-view conversion, range check, typed cut[T] or newArray + copy) and retains nothing. The generated threaded handler and the callout both call it, as concat is shared. Interpreter.share retains a ref array's elements after alloc, so a heap-exhaustion panic leaves every count unchanged. This keeps the handler's existing order.
  • Callout.
    • callouts[ARRAY_SLICE]; the callout args widen from 2 to 3.
    • Operands keep the callout contract: ARRAY_SLICE adopts none (transform.Adopts is 0), so native code keeps and releases the container, exactly once, as for STRING_CONCAT.
    • A host view panics in the callout and deopts, matching engine.bridge's hosted rule, so host conversion never runs under native code.
  • Docs: the jit-internals.md Callout row.

Evidence

  • TestWithThreshold new subtest:

    • typed and ref arrays, range/empty/full: results and ref counts equal threaded;
    • four trap cases (end past length typed/ref, negative start, start past end): same error and counts as threaded.

    Limitation: vm_jit_exits_total{kind="bridge"} counts callouts too, since both are ExitBridge, so no test pins callout vs bridge. This test is a parity guard, and the A/B below is the evidence of the change.

  • Local A/B (6 × 300 ms): fannkuch about −7% (131.0 → 122.5 µs). sort-stress and permutation-flips are within noise; only fannkuch slices. The CI report decides.

  • make generate && make check-generated (the diff only replaces the inline body with calls), go test ./interp ./internal/..., make check, git diff --check: pass.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 058c8c29-756d-4ade-b3b6-c0892114fc36
Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@siyul-park
siyul-park force-pushed the perf/jit-slice-callout branch from 86a7479 to 5ffc6a4 Compare November 10, 2026 00:52
ARRAY_SLICE had no lowering, so each one bridged: a scratch frame,
operand retains and a handler run. fannkuch bridged it 720 times per
Run, 28% of its CPU. The op only allocates a copy, the class callouts
serve: Go computes the object from the operand words and native code
keeps ownership of the operands.

The slice semantics move into Interpreter.slice, which the threaded
handler and the callout both call (as concat is shared); share retains
a ref array's elements after its allocation, so a heap-exhaustion panic
leaves every count unchanged. A host view still deopts. Callout
arguments widen to three.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@siyul-park
siyul-park force-pushed the perf/jit-slice-callout branch from 4a0d914 to 6c09e1c Compare November 10, 2026 04:03
@siyul-park
siyul-park merged commit 4eb0da7 into main Nov 10, 2026
2 checks passed
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