Use datastack path for __init__ dispatch in CallAllocAndEnterInit - #8448
Use datastack path for __init__ dispatch in CallAllocAndEnterInit#8448youknowone wants to merge 1 commit into
Conversation
specialization_run_init used prepare_exact_args_frame which heap-allocates a FrameObject with 4-5 atomic refcount bumps per call. Switch to invoke_prepared_exact_args which uses InterpreterFrame::new_on_datastack with zero refcount bumps. CallAllocAndEnterInit already guards against tracing (eval_frame_active) and recursion limits before reaching this path. Assisted-by: Claude
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe change makes ChangesInitializer invocation
Estimated code review effort: 2 (Simple) | ~5 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
This PR optimizes CallAllocAndEnterInit’s __init__ dispatch by switching from a heap-allocated FrameObject path to a datastack-based invocation path, reducing refcount churn and allocation overhead.
Changes:
- Replace
prepare_exact_args_frame+run_frame+release_datastack_framewithinvoke_prepared_exact_argsinspecialization_run_init. - Widen visibility of
invoke_prepared_exact_argstopub(crate)to enable reuse fromframe.rs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/vm/src/frame.rs | Uses the datastack fast-path invocation for __init__ instead of allocating a frame object. |
| crates/vm/src/builtins/function.rs | Exposes invoke_prepared_exact_args within the crate to support the new call site. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let init_result = vm.run_frame(init_frame.clone()); | ||
| release_datastack_frame(&init_frame, vm); | ||
| let init_result = init_result?; | ||
| let init_result = init_func.invoke_prepared_exact_args(taken, vm)?; |
| pub(crate) fn invoke_prepared_exact_args( | ||
| &self, | ||
| args: impl ExactSizeIterator<Item = PyObjectRef>, | ||
| vm: &VirtualMachine, |
Summary
specialization_run_init(used byCallAllocAndEnterInit) calledprepare_exact_args_framewhich heap-allocates aFrameObjectwith 4-5 atomic refcount bumps per call. This switches toinvoke_prepared_exact_argswhich usesInterpreterFrame::new_on_datastack+run_frame_fastwith zero refcount bumps on code/globals/builtins/func_obj.Part of #40.
Safety
CallAllocAndEnterInitalready guards against:specialization_eval_frame_active)specialization_call_recursion_guard)specialization_has_datastack_space_for_func)These are the same guards used by
CallPyExactArgswhich already uses the datastack path.Changes
frame.rs:specialization_run_init— replaceprepare_exact_args_frame+run_frame+release_datastack_framewithinvoke_prepared_exact_argsfunction.rs:invoke_prepared_exact_argsvisibilityfn→pub(crate) fnSummary by CodeRabbit