Closed Bug 1844878 Opened 2 years ago Closed 3 months ago

Improve preservation of DOM wrappers

Categories

(Core :: JavaScript Engine, task, P1)

task

Tracking

()

RESOLVED FIXED
141 Branch
Size Estimate M
Tracking Status
firefox141 --- fixed

People

(Reporter: iain, Assigned: alexical)

References

(Blocks 6 open bugs)

Details

(Whiteboard: [sp3][js-perf-next])

Attachments

(1 file, 1 obsolete file)

To ensure that we don't lose information when assigning a property to a DOM wrapper object and then discarding the wrapper, the code that autogenerates our DOM classes creates an addProperty hook for each class. One significant downside of this approach is that we have to call the hook whenever a property is added, even though every call after the first is redundant. In addition to the overhead of the calls, this also impedes optimization in some cases, because the hook could have arbitrary side-effects.

I've seen this show up in a few places in sp3 perf reports: for example, selection_select in charts-observable-plot, and Ni in React-stockcharts.

One alternative would be to add a new class flag that tells the engine to call a callback whenever the first property is added to an object. This would reduce unnecessary overhead.

Attached file WIP: Bug 1844878: WIP wrapper hook (obsolete) —

This is an extremely rough first draft. It doesn't even compile yet.

Blocks: speedometer3
Whiteboard: [sp3]

I've been trying to estimate the benefit of this optimization but I'm not sure what work it would eliminate.

In this full sp3 profile I found 500 samples in CallAddPropertyHook, which corresponds to 0.27% of sp3 overall. How much of the work in this profile would we expect this fix to eliminate?

I also see CallAddPropertyHook called in this TodoMVC-Angular comparison report in the two functions at position #4 and #6.

Flags: needinfo?(iireland)

It's a little tricky to estimate. This patch eliminates calls to the add property hook after the first one, but the first one is the expensive one anyway. On the other hand, it also lets us use faster paths for subsequent addprops, which is hard to measure without just writing the patch. To some extent, the improvement depends on the fraction of wrapper objects that have more than one property added.

As a rough estimate: the samples in that profile inside nsWrapperCache::PreserveWrapper are mostly still necessary (except for the if (PreservingWrapper()) return; part, which I'm assuming is trivial). Dropping the two implementations of that function leaves 174/500 samples. I would hope for the fix to eliminate a solid chunk of those samples.

The amount of code left to be written is relatively small. Mostly I just need to find time to talk to a DOM person about making the DOM-side code of my prototype less criminal.

Flags: needinfo?(iireland)

Ah I see. Thanks!

My notes say I've seen this problem in Backbone, Preact, WebComponents, Charts-observable, CodeMirror, TipTap, React, ReactRedux, and NewsSite-Next. Not all of them are hot enough to move the needle a lot, but collectively it seems like it would be good to get this finished.

js-perf-next: Get my draft patch working. I think the code inside SpiderMonkey is relatively complete; the missing part is finding a way to rewrite dom::TryPreserveWrapper so that we can call it from inside SM without going through the addProp hook that we're trying to remove.

Whiteboard: [sp3] → [sp3][js-perf-next]
See Also: → 1917031, 1892764
Blocks: 1606600
Duplicate of this bug: 1926472
Size Estimate: --- → M

This patch replaces the use of the addProperty hook to preserve DOM wrappers
in favor of calling the wrapper preservation directly based on a class flag.
This additionally allows us to add an object flag on the shape indicating
that objects with that shape have already had their wrappers preserved,
avoiding redundant calls and allowing us to remain in the JIT for objects
with already preserved wrappers.

Assignee: nobody → dothayer
Status: NEW → ASSIGNED
Blocks: 1354015
Duplicate of this bug: 1353928
Pushed by dothayer@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/f6ba67f510be Eliminate redundant addProperty calls for wrapper preservation r=smaug,jandem

Backed out for causing multiple failures

Backout link

Push with failures

A few failure logs:
xpc test_inspectFields.js https://treeherder.mozilla.org/logviewer?job_id=508742430&repo=autoland&lineNumber=3748
mochitest test_bug655297-1.html https://treeherder.mozilla.org/logviewer?job_id=508739329&repo=autoland&lineNumber=2976
bc failures browser_UrlbarInput_searchTerms_searchMode.js https://treeherder.mozilla.org/logviewer?job_id=508743999&repo=autoland&lineNumber=4074
bc failures browser_anti_clickjacking.js https://treeherder.mozilla.org/logviewer?job_id=508739417&repo=autoland&lineNumber=3450

Please check this range to check failure logs

Flags: needinfo?(dothayer)
Pushed by chorotan@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/82c5c8d58fc2 Revert "Bug 1844878 - Eliminate redundant addProperty calls for wrapper preservation r=smaug,jandem" for causing multiple failures
Attachment #9487420 - Flags: approval-mozilla-beta?

Comment on attachment 9487420 [details]
Bug 1844878 - Eliminate redundant addProperty calls for wrapper preservation r=iain!,smaug!

Removing beta uplift request flag, added due to Bug 1844878

Attachment #9487420 - Flags: approval-mozilla-beta?
Pushed by dothayer@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/76db8d178062 Eliminate redundant addProperty calls for wrapper preservation r=smaug,jandem
Status: ASSIGNED → RESOLVED
Closed: 3 months ago
Resolution: --- → FIXED
Target Milestone: --- → 141 Branch
Flags: needinfo?(dothayer)
Attachment #9345145 - Attachment is obsolete: true
Blocks: 1973249
QA Whiteboard: [qa-triage-done-c142/b141]
Blocks: 1974519
Regressions: 1980081
Blocks: 1981272
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: