perf(codegen): skip canonical-shape own-method scans - #8505
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 8 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughThe change adds canonical class/ShapeId validation to dynamic method dispatch. Eligible receivers skip the own-property probe, while unsupported or mismatched cases retain existing fallback behavior. Tests cover inherited methods, declared function fields, property mutation, and ShapeId guard dataflow. ChangesDynamic dispatch shape validation
Estimated code review effort: 3 (Moderate) | ~25 minutes Merge Risk: ⚪ Minimal · up to This change adds a guarded dispatch fast path while preserving fallback behavior for mutable or non-canonical instances; the supplied checks and regression coverage support merge readiness with no actionable merge-blocking risk remaining. Sequence Diagram(s)sequenceDiagram
participant Receiver
participant DynamicDispatch
participant RuntimeMetadata
Receiver->>DynamicDispatch: provide receiver
DynamicDispatch->>RuntimeMetadata: read class ID and ShapeId
RuntimeMetadata-->>DynamicDispatch: return metadata
DynamicDispatch->>DynamicDispatch: compare canonical class/ShapeId pair
DynamicDispatch->>DynamicDispatch: skip or run own-property probe
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 |
|
Audited and merging. The performance claim is fine; the review here is the soundness of the proof, since a wrong "no own override" verdict silently resolves a method to the prototype when an own property should have shadowed it — that is a wrong-answer bug, not a slow one. The compile-time half is conservative in the right ways. The runtime half rests on I verified the new path is actually exercised before trusting any probe. My first two adversarial fixtures passed against Node while emitting zero new arms — the counts were identical to On With a fixture built to that shape (
Output Also ran the two gates this PR skipped. The test plan reports "all 50 lint gates" because it used |
Summary
Speed up polymorphic instance-method dispatch by using an exact compiler-published
(class_id, ShapeId)pair to prove that canonical instances have no own-method override. This removes the hotjs_object_get_own_field_or_undefkeys scan from eligible calls and reuses the class ID for the bounded dispatch tower.Declared or computed fields, dynamic inheritance, post-construction shape changes, descriptor/prototype invalidation, non-instance receivers, and wide towers keep the existing guarded fallback.
Changes
Related issue
Fixes #8406
Performance
Quiet A/B measurement for this change:
shapesretired instructions: -9.14%shapesCPU cycles: -9.93%A fresh alternating 21-run sample on the currently contended host still clears the issue's wall-time criterion:
The same local
/usr/bin/time -lsample reported median retired instructions / peak RSS of 1,149,921,569 / 33,914,880 bytes for Perry and 1,090,746,015 / 94,044,160 bytes for Node. The machine was at load average ~70, so the alternating high-resolution wall sample is reported separately from the quiet A/B compute deltas above.Test plan
cargo build --release -p perry -p perry-runtime-static -p perry-stdlib-staticcargo test --release -p perry-runtime --lib— 2,606 passed, 4 ignoredcargo test --release -p perry --bin perry— 1,008 passedcargo test --release -p perry --test issue_8406_dynamic_dispatch_shape_probecargo test --release -p perry-codegen --lib tower_route_is_guarded_by_the_class_shape_idBASE_SHA=upstream/main SKIP_COMPILE_GATES=1 bash scripts/run_lint_gates.sh— all 50 lint gates passedcargo fmt --all -- --checkChecklist
CLAUDE.mdorCHANGELOG.mdchangesSummary by CodeRabbit
Performance
Bug Fixes
Tests