Skip to content

perf: add bounded polymorphic object-write PIC#6823

Merged
proggeramlug merged 3 commits into
PerryTS:mainfrom
proggeramlug:perf/6812-polymorphic-write-pic
Jul 24, 2026
Merged

perf: add bounded polymorphic object-write PIC#6823
proggeramlug merged 3 commits into
PerryTS:mainfrom
proggeramlug:perf/6812-polymorphic-write-pic

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Expand generated write PIC storage to four bounded shape/slot entries.
  • Prime entries in order, consulting the next entry only after earlier shape mismatches.
  • Reuse all existing receiver, descriptor, forwarding, class, shape-token, and slot-bound guards on every hit path.
  • Keep higher-polymorphism and exotic sites on the complete semantic fallback path.

Evidence

The two-shape cell improved from roughly 5.3 s to 667 ms in the measured release run, with matching checksums. Monomorphic writes remain 123 ms vs Node 133 ms. The final four-shape release sweep (15 alternating Node/Perry pairs) measured Node median 110 ms and Perry median 461 ms, with 60,000,000 writes and checksum 62,876,400 on every sample.

Validation

  • cargo fmt --all -- --check
  • git diff --check
  • cargo test -p perry-codegen --test native_proof_regressions — 250 passed

Summary by CodeRabbit

  • New Features
    • Improved object property write performance by extending the bounded polymorphic write inline-cache to retain multiple stable shape entries (up to four).
  • Bug Fixes
    • Improved correctness and miss accounting for polymorphic write paths, including more precise handling of bounded clone rejection and mutable/exotic cases.
  • Documentation
    • Updated benchmark documentation with four-entry results and added a changelog note describing the optimization.
  • Tests
    • Strengthened native regression coverage for polymorphic inline-cache miss behavior and bounded clone rejection expectations.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Static object-write inline caches now support four bounded shape/slot entries. IC backing globals expand to hold the entries, code generation adds guarded hit and miss paths, and native regressions, benchmark results, and changelog documentation are updated.

Changes

Polymorphic write PIC

Layer / File(s) Summary
Expand inline-cache backing storage
crates/perry-codegen/src/codegen/{closure,entry,function,method}.rs
IC globals now use larger zero-initialized backing arrays for bounded polymorphic entries.
Add guarded four-entry write paths
crates/perry-codegen/src/expr/proxy_reflect.rs
Static writes consult cached entries two through four after earlier entries, select the matching slot, and preserve per-entry runtime miss handling.
Verify and document bounded behavior
crates/perry-codegen/tests/native_proof_regressions.rs, benchmarks/object-write-6812/followup-polymorphic-shapes.md, changelog.d/6812-polymorphic-write-pic.md
Regression assertions require four bounded guard/miss paths, while benchmark and changelog content describe the four-entry behavior and measured results.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related issues

  • PerryTS/perry issue 6812 — Directly covers the bounded polymorphic write PIC implemented here.

Possibly related PRs

  • PerryTS/perry#6807 — Provides the runtime shape/token representation used by the expanded PIC.
  • PerryTS/perry#6811 — Introduces the static-key write PIC structure extended by this change.
  • PerryTS/perry#6821 — Modifies the same static write PIC lowering and cache handling.

Sequence Diagram(s)

sequenceDiagram
  participant WriteSite
  participant InlineCache
  participant Runtime
  WriteSite->>InlineCache: Check cached shape and slot entries one through four
  InlineCache-->>WriteSite: Return matching slot or miss path
  WriteSite->>Runtime: Call js_put_value_set_ic_miss with the selected token
  Runtime-->>WriteSite: Return miss result
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: adding a bounded polymorphic object-write PIC.
Description check ✅ Passed The description covers summary, evidence, and validation, but it omits the template's Changes, Related issue, and Checklist sections.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
crates/perry-codegen/src/expr/proxy_reflect.rs (1)

397-399: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Update the stale "second entry" comment for the new 4-entry cascade.

This comment still only describes a two-entry design, but the block below it is now the first link in a four-guard chain (guard2 → dispatch3 → guard3 → dispatch4 → guard4). Worth expanding to describe the full bounded-cascade behavior so the control flow here isn't misread as two-entry.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/perry-codegen/src/expr/proxy_reflect.rs` around lines 397 - 399,
Update the comment preceding the cache cascade in the proxy-reflection code to
describe the full four-entry bounded cascade, including the guard2 → dispatch3 →
guard3 → dispatch4 → guard4 progression. Remove the outdated two-entry wording
while preserving the explanation that the initial entry is filled first and
later distinct shapes advance through the cascade without changing the miss ABI.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/perry-codegen/tests/native_proof_regressions.rs`:
- Around line 13485-13489: Extend the write PIC assertions in the regression
test to require both put.pic.miss2 and put.pic.miss3 in addition to the existing
miss checks. Keep the guard2, guard3, guard4, and miss4 assertions unchanged so
all four bounded shape miss paths are validated.

---

Nitpick comments:
In `@crates/perry-codegen/src/expr/proxy_reflect.rs`:
- Around line 397-399: Update the comment preceding the cache cascade in the
proxy-reflection code to describe the full four-entry bounded cascade, including
the guard2 → dispatch3 → guard3 → dispatch4 → guard4 progression. Remove the
outdated two-entry wording while preserving the explanation that the initial
entry is filled first and later distinct shapes advance through the cascade
without changing the miss ABI.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c6ea45d9-5f6b-4134-b5ea-c67e73ccded6

📥 Commits

Reviewing files that changed from the base of the PR and between 1c29a18 and d8fa924.

📒 Files selected for processing (7)
  • benchmarks/object-write-6812/followup-polymorphic-shapes.md
  • crates/perry-codegen/src/codegen/closure.rs
  • crates/perry-codegen/src/codegen/entry.rs
  • crates/perry-codegen/src/codegen/function.rs
  • crates/perry-codegen/src/codegen/method.rs
  • crates/perry-codegen/src/expr/proxy_reflect.rs
  • crates/perry-codegen/tests/native_proof_regressions.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • crates/perry-codegen/src/codegen/entry.rs
  • crates/perry-codegen/src/codegen/method.rs

Comment on lines +13485 to +13489
ir.contains("put.pic.guard2")
&& ir.contains("put.pic.guard3")
&& ir.contains("put.pic.guard4")
&& ir.contains("put.pic.miss4"),
"the write PIC should retain four bounded shape entries"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert the second and third miss paths too.

The existing generic put.pic.miss check only covers the first entry, while this new assertion checks only put.pic.miss4 explicitly. Add put.pic.miss2 and put.pic.miss3; otherwise either path could regress while the “four bounded shape entries” assertion still passes.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/perry-codegen/tests/native_proof_regressions.rs` around lines 13485 -
13489, Extend the write PIC assertions in the regression test to require both
put.pic.miss2 and put.pic.miss3 in addition to the existing miss checks. Keep
the guard2, guard3, guard4, and miss4 assertions unchanged so all four bounded
shape miss paths are validated.

@proggeramlug
proggeramlug merged commit f6fb9a4 into PerryTS:main Jul 24, 2026
29 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