Repository navigation
perf(runtime): run native property setters from the canary write handler - #578
Draft
edusperoni wants to merge 1 commit into
Draft
edusperoni wants to merge 1 commit into
edusperoni wants to merge 1 commit into
Conversation
A native property write on a canary went through the write handler, which declined, and then through V8's own store lookup and its call of the accessor's setter function. The handler now runs the native setter itself when the accessor its prototype walk found is provably the one MetadataBuilder installed: - in canary mode each native class prototype carries, under a private key, the PropertyMeta setters it was built with; - the prototype's own setter and definer interceptors forget a name for good once JS assigns or defines it on that prototype, so a redefined accessor is never mistaken for the native one; - the owner must be the first object of the chain with the name, so a JS accessor or data property anywhere below it still wins. The setter runs through the same code as the accessor's callback (SetNativeProperty), so dispatch, proxy handling and exceptions are unchanged.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #561 (canary wrapper lifetime mode), as its own PR so it can be reverted on its own after the squash merge. It makes native ObjC property writes on canaries cheaper; nothing else changes.
Current behavior
In canary mode, a write to a native property on a canary (
view.tag = 1on an instance of a JS-extended class, or on any wrapper under"scope": "all") goes through the canary write handler first. The handler classifies the name with a prototype-chain walk, finds a native accessor, declines, and V8 then redoes the store lookup and calls the accessor's setter function from C++. That costs about 2.5–3× a native write inresurrecting.New behavior
The write handler runs the native setter itself when the accessor its walk found is provably the one
MetadataBuilderinstalled:RegisterInstancePropertiesrecords each settable native property it installs. The native class prototype carries the table under a private key: internalized name →PropertyMeta, last install wins.defineProperty,defineProperties,Reflect.definePropertyand__defineSetter__all reach the definer. A deleted accessor stops being found by the walk, re-adding the name by assignment makes it a data property (not an accessor), and re-adding an accessor needs a define, which the definer sees.SetNativeProperty(read-only error, proxy receiver resolution,InvokeMethod), and the fast path calls that same function. Dispatch, KVO, swizzle aliases and exceptions are identical by construction.Read-only native properties aren't in the table, so V8 still rejects them; setter-less properties keep today's path.
V8 invariant to recheck on upgrades: this assumes the only JS route to a new accessor on a native prototype is a define that reaches that prototype's definer.
Performance
Release, simulator, 5 alternating rounds per configuration, medians in ns, against #561:
UIButton:tagwrite, 4 levels upUIButton:tagwriteEvery other row (native calls and reads, expando reads and writes, misses, first write of a new name, creation, re-reading after GC, full GC) is within noise.
resurrectingis unchanged.Not measured: the memory of the tables (one
Global<Name>per settable native property per class touched, per isolate). An error thrown by a setter through the fast path may lack the native accessor's API frame inerror.stack.Testing
write handler›native property setters). They pass with and without this change: sloppy and strict writes, an ObjC exception from a setter, read-only rejection, a JS override, an accessor added later on the JS prototype or on the instance, the four routes that redefine a member on the native prototype, delete and re-add there, a Proxy prototype, and a setter override exposed to native code.canary/allfails 8 suites, including the existing swizzle and JS-accessor-encoding suites, so the specs do cover it.resurrecting/extended,canary/all,canary/extendedandrooted/all; ASan,canary/all: 0 failures, no reports.