Skip to content

perf(interp): admit ref returns on the native call boundary - #195

Merged
siyul-park merged 1 commit into
mainfrom
perf/jit-ref-returns
Aug 16, 2026
Merged

siyul-park merged 1 commit into
mainfrom
perf/jit-ref-returns

Conversation

@siyul-park

Copy link
Copy Markdown
Owner

Split out of #191. Stacked on #191.

Change

checkReturns rejected every non-scalar return kind, so a CALL to a function returning a ref rejected the whole plan — observed as a lowering rejection on opcode CALL for the StructTreeWalk and BinaryTrees kernels, which build a node and return it.

This admits KindRef and pushes the result the way ARRAY_GET and STRUCT_GET already do: boxed (raw: false), owning exactly one retain, so l.kinds' generic !v.raw check cannot later mistake a ref for an unboxed payload.

This does not move any kernel

Stated plainly because the framing matters for review: this is lowering coverage, not a speedup.

  • StructTreeWalk and BinaryTrees still reject at their ref STRUCT_SET, which stays terminal
  • AllocationGraph is bound by its per-iteration ARRAY_NEW_DEFAULT bridge, not by any return

Measured on Apple M4 Pro, darwin/arm64, -benchtime=300ms -count=3: no kernel moved outside run-to-run drift.

Also pins the rule that actually blocks those kernels

TestARM64_RefContainerStoreRemainsTerminal covers both ARRAY_SET and STRUCT_SET. Dropping the kind == types.KindRef disjunct from their terminal tails was tried and reverted for each: a ref store whose native continuation is nested inside a native self-recursive call drives refcounts negative against a threaded twin from recursion depth two upward, while depths zero and one pass — so the shallow tests that first accepted the change did not see it.

The interaction is not yet root-caused. The test exists so the same change is not made a third time. docs/jit-internals.md records the cost of keeping the rule: a terminal store that is not its block's last step makes steps report ok=false, rejecting the whole plan rather than truncating the block, so a ref store mid-loop-body keeps its entire function threaded.

Test plan

  • TestARM64_RefReturn gains a self-recursive sub-case through selfCall; fails without the KindRef admission with expected native code to be installed
  • TestARM64_RefContainerStoreRemainsTerminal at depths 0/1/2/3/5/8 for both container kinds
  • go test -race ./..., make check-generated

Refs #164

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@siyul-park, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 34 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: cc07e83c-078f-4f61-8987-092827236417

📥 Commits

Reviewing files that changed from the base of the PR and between 6fb3493 and 31531d5.

📒 Files selected for processing (3)
  • docs/jit-internals.md
  • interp/jit_arm64.go
  • interp/jit_arm64_test.go

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.

@siyul-park
siyul-park force-pushed the perf/jit-ref-returns branch from d169f94 to 7460f59 Compare August 16, 2026 00:48
@siyul-park
siyul-park force-pushed the perf/jit-static-self-recursion branch 2 times, most recently from 480d44c to 25079c8 Compare August 16, 2026 00:58
@siyul-park
siyul-park force-pushed the perf/jit-ref-returns branch from 7460f59 to 96f6b11 Compare August 16, 2026 00:59
@siyul-park
siyul-park changed the base branch from perf/jit-static-self-recursion to main August 16, 2026 00:59
checkReturns rejected every non-scalar return kind, so a CALL to a function
returning a ref rejected the whole plan - observed as a lowering rejection on
opcode CALL for the StructTreeWalk and BinaryTrees kernels, which build a node
and return it. Admit KindRef and push the result the way ARRAY_GET and
STRUCT_GET already do, boxed (raw: false) and owning exactly one retain, so
l.kinds cannot later mistake a ref for an unboxed payload.

This widens lowering coverage; it does not move any kernel. StructTreeWalk and
BinaryTrees still reject at their ref STRUCT_SET, which stays terminal, and
AllocationGraph is bound by its per-iteration ARRAY_NEW_DEFAULT bridge rather
than by any return. Measured on Apple M4 Pro, darwin/arm64, -benchtime=300ms
-count=3: no kernel moved outside run-to-run drift.

Also pins the ref container store rule that blocks those kernels.
TestARM64_RefContainerStoreRemainsTerminal covers both ARRAY_SET and
STRUCT_SET, because dropping the kind == KindRef disjunct was tried and
reverted for each: a ref store whose native continuation is nested inside a
native self-recursive call drives refcounts negative against a threaded twin
from depth two upward, while depths zero and one pass, so the shallow tests
that first accepted the change did not see it. The interaction is not yet
root-caused, so the test exists to stop the same change being made a third
time.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@siyul-park
siyul-park force-pushed the perf/jit-ref-returns branch from 96f6b11 to 31531d5 Compare August 16, 2026 01:00
@siyul-park
siyul-park merged commit c1c9aff into main Aug 16, 2026
1 of 2 checks passed
@siyul-park
siyul-park deleted the perf/jit-ref-returns branch August 16, 2026 01:00
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