Skip to content

feat(patches): fast path for stores a masking interceptor declines - #15

Merged
edusperoni merged 2 commits into
mainfrom
feat/declined-interceptor-store-fast-path
Nov 21, 2026
Merged

edusperoni merged 2 commits into
mainfrom
feat/declined-interceptor-store-fast-path

Conversation

@edusperoni

@edusperoni edusperoni commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

What

Adds patches/v8_declined_interceptor_store_fast_path.patch and applies it in scripts/matrix/fetch.sh on every platform, after v8_interceptor_define_descriptor.patch (the iOS-only Catalyst patch still applies after it). README row added.

When a masking named interceptor's setter declines a store (Intercepted::kNo), V8 14.9 always finishes the store in Runtime_StorePropertyPastInterceptor. That redoes the lookup and runs a generic Object::SetProperty, even when the store just overwrites an existing own field. The runtimes' write-observing setters mirror each write and then decline, so they pay this on every property write.

How

  • When the IC is computed (StoreIC::ComputeHandler, INTERCEPTOR case): a side-effect-free own lookup that skips the interceptor checks whether the receiver map has an own, writable, fast-mode data field (kField) for the name. If it does, the interceptor store handler gets a bit plus the field's descriptor index, in new smi bits after NonMaskingInterceptorBits.
    • Excluded at this point: non-masking interceptors, define stores, global proxies and objects, access-checked maps, dictionary-mode and deprecated maps, element keys, and protector names.
  • When the store runs, after a declined setter: if the bit is set, the receiver still has the map it had before the setter ran, that map isn't deprecated, and the cached descriptor still has this name and is still a writable data field, the handler calls OverwriteExistingFastDataProperty(). That function reads constness, representation and field type live, so const fields and values that need generalization go to the runtime.
  • Every bailout tail-calls Runtime::kStorePropertyPastInterceptor, never an IC miss, so the setter is never called twice. When the setter throws, the builtin's exception exit unwinds before the new code runs (checked in CallApiFunctionAndReturn on every architecture).
  • The behaviour should be unchanged; only the speed changes. --no-store-ic-declined-interceptor-fast-path turns it off. With the flag off, the compute-time bit is never set and every store takes today's path.
  • New counters: V8.StorePropertyPastInterceptor (a stats counter, used by the tests) and the RCS handler counter StoreIC_StoreInterceptorOwnFieldDH.
  • Upstream: not submitted yet; the patch is meant to become an upstream CL. This PR is a draft so CI builds Android and iOS artifacts for measuring in the Android and iOS runtimes.

Testing (local, macOS arm64, release + dcheck_always_on + verify_heap, 14.9.207.39 with the existing patches)

New cctests test-api-interceptors/DeclinedInterceptorStore*:

  • Fast path: monomorphic, polymorphic and megamorphic stores; in-object and out-of-object fields; keyed stores with a constant name; stores from Maglev and Turbofan code.
  • Representations: Smi, Double, Smi→Double (map deprecation), Smi/Double→Tagged, heap-object field type mismatch.
  • Constness: the first overwrite of a const field goes to the runtime, later ones take the fast path.
  • 21 setter side effects: delete, delete and re-add, add another property, normalize, make read-only (sloppy and strict), turn into an accessor, freeze/seal/preventExtensions, change prototype (including away and back), deprecate or generalize via a sibling, throw, write the property itself, used as a prototype.
  • Exclusions: non-masking interceptor, kOnlyInterceptStrings with a symbol key, class fields, access-checked object, interceptor on the prototype, dictionary mode, adding a missing property, protector names, global proxy.

How the tests check it:

  • Every scenario runs once through IC'd store sites and once through Reflect.set.
  • The setter must run exactly once per store, not counting calls made by the side effect itself.
  • The final object state of the two runs must match.
  • Each store must take the expected path (fast, runtime or miss). The tests tell these apart with the new stats counter plus the setter's caller frame.

Matrix:

  • Variants: default, --no-lazy-feedback-allocation, --maglev, --turbofan, --always-sparkplug, --jitless, --no-use-ic, --stress-ic (interceptor suite only), fast path off, and fast path off with --jitless.
  • The new tests pass in every variant.
  • test-api-interceptors, test-api and test-accessors fail on exactly the same tests as the unpatched binary in each variant. Those failures are expected-fail or variant-incompatible.

CI here only builds v8_monolith, so the cctests ran only locally.

Benchmark

Same binary, fast path on vs off, hot loop overwriting an existing field. Medians of 4 interleaved runs × 7 reps × 2M stores, in ns/store:

Setter off on
declines immediately 153.6 8.8 (17×)
mirrors the write into another object, then declines 299.5 148.6 (2.0×)
intercepts (kYes), reference ~9.6 ~9.6
no interceptor, reference ~3.8 ~3.8

Follow-up commit

  • Adds CSA_DCHECKs where the handler loads the cached descriptor: the map is not in dictionary mode, needs no access check, and the index is below the own descriptor count.
  • Leaves the fast path out of define-own handlers at code generation time.
  • Adds the cctest DeclinedInterceptorStoreGCInSetter: the setter runs a minor GC, a major GC or a forced compaction of the receiver's pages before it declines, for Smi, double and tagged fields.
  • test-api-interceptors passes under --verify-heap, --stress-compaction, --gc-interval=500 and =10, --stress-incremental-marking, and --stress-scavenge=100 and =10, in addition to the earlier variants. The only remaining failure is Regress256330 under --no-use-ic, which fails the same way without the patch.
  • Turning the flag off restores behaviour but not identical code: the handler still loads the receiver map, and the runtime still increments the stats counter.

A masking named interceptor whose setter declines (Intercepted::kNo) makes
V8 finish every store in Runtime_StorePropertyPastInterceptor, which redoes
the lookup and runs a generic SetProperty even when the store just
overwrites an existing own field. The runtimes' write-observing setters
mirror each write and decline, so they pay this on every property write.

v8_declined_interceptor_store_fast_path.patch records in the store IC
handler, when the IC is computed, whether the receiver map has an own,
writable, fast-mode data field for the name and its descriptor index.
After a declined setter, the handler overwrites that field in place when
the receiver kept the same, non-deprecated map; constness, representation
and field type are read live, so const fields and values that need
generalization go to the runtime. Every bailout continues in the runtime,
never through an IC miss, so the setter runs once. Globals, access-checked
and dictionary-mode receivers and protector names are excluded when the
IC is computed. --no-store-ic-declined-interceptor-fast-path turns it off.
Not yet submitted upstream. Applied on every platform.

Tested locally on macOS arm64 (release, dcheck_always_on, verify_heap) on
14.9.207.39 with the existing patches: new cctests DeclinedInterceptorStore*
(fast path hit mono/poly/megamorphic, in-object and out-of-object, keyed,
Maglev/Turbofan code; representations; constness; 21 setter side effects;
exclusions) check that the setter runs once per store and that the final
state matches Reflect.set. test-api-interceptors, test-api and
test-accessors have the same failures as without the patch under default
flags, --no-lazy-feedback-allocation, --maglev, --turbofan,
--always-sparkplug, --jitless, --no-use-ic and with the fast path off.

Same binary, fast path on vs off, existing-field overwrite in a hot loop:
setter that declines at once 153.6 -> 8.8 ns/store; setter that mirrors
the write into another object then declines 299.5 -> 148.6 ns/store.
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1b9b651b-0ffb-4197-a1fe-fd5b7e458385

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • 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

Adds CSA_DCHECKs where the handler loads the cached descriptor (map not
in dictionary mode, no access check, index below the own descriptor
count) and leaves the fast path out of define-own IC handlers at code
generation time; ComputeHandler already gives those a slow handler.

New cctest DeclinedInterceptorStoreGCInSetter runs a minor GC, a major
GC or a forced compaction of the receiver's and its property array's
pages from inside the declining setter, for Smi, double and tagged
fields, and checks the fast path still writes the right object. Path
assertions tolerate cleared feedback under GC stress flags.

Locally (macOS arm64, release + dcheck_always_on + verify_heap) all of
test-api-interceptors passes under default flags,
--no-lazy-feedback-allocation, --maglev, --turbofan, --always-sparkplug,
--jitless, --stress-ic, --verify-heap, --stress-compaction,
--gc-interval=500 and =10, --stress-incremental-marking,
--stress-scavenge=100 and =10, and with the fast path off; only the
pre-existing Regress256330 failure under --no-use-ic remains. test-api and
test-accessors fail exactly as without the patch (default, fast path off,
--stress-compaction).

The README row notes that turning the flag off restores behaviour but not
identical code.
@edusperoni
edusperoni marked this pull request as ready for review November 21, 2026 20:07
@edusperoni
edusperoni merged commit b1e1251 into main Nov 21, 2026
17 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