cdjs has multiple roots constructed 30,000,000+ times over execution.
Categories
(Core :: JavaScript Engine, task, P3)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox141 | --- | fixed |
People
(Reporter: mgaudet, Assigned: anba, Mentored)
References
(Blocks 1 open bug)
Details
Attachments
(1 external file)
Looking at the cdjs root report: https://github.com/mgaudet/root-reports/blob/main/cdjs-roots#L7543C1-L7572C12
We see
- 35801502 x 2 roots in js::intl_CompareStrings
- 33703140 roots in AutoStableStringChars (unclear why duplicated)
| Reporter | ||
Comment 1•1 year ago
|
||
js::intl_CompareStrings seems a prime candidate for RootedTuple.
| Assignee | ||
Comment 2•1 year ago
|
||
"unnecessary.txt" from shell-hazard claims the rooting isn't actually necessary in AutoStableStringChars and intl_CompareStrings.
| Reporter | ||
Updated•1 year ago
|
Comment 3•1 year ago
|
||
(In reply to André Bargull [:anba] from comment #2)
"unnecessary.txt" from shell-hazard claims the rooting isn't actually necessary in
AutoStableStringCharsandintl_CompareStrings.
mgaudet pointed me at these.
The root in AutoStableStringChars looks to be wholly superfluous. The callee already accepts a bare JSString* and roots it itself. Not only that, but both the caller and calle call ensureLinear on the same string. I think the caller could be simplified to just pass value.toString() directly to initTwoByte.
intl_CompareStrings is more nuanced. The hazard analysis is saying that rooting collator is unnecessary because it's just getting passed into GetOrCreateCollator and never used again. Which is true, except that if it didn't root it, then GetOrCreateCollator would need to root it instead. Generally, we try to root as high up as we can to avoid re-rooting overhead. So the analysis is sort of "correct but wrong" here -- it's correct that the rooting does nothing for the intl_CompareStrings caller, but wrong in implying that the rooting should be removed.
The unnecessary rooting report is old and unloved, and perhaps it could be made smarter with heuristics (eg if there are multiple callers of a function foo(obj), then say it's ok to make all callers pass in a Handle even if not all of them require rooting themselves. Note that this would not resolve the intl_CompareStrings case, because there's a single caller and so the analysis is really implying that GetOrCreateCollator should accept a raw pointer and root internally. Which wouldn't change the amount of rooting happening, but would stop implying via a Handle parameter that there's a good reason why callers should have already rooted things being passed in. I'm not sure what heuristic would work here. I guess something that expresses "if the amount of rooting is the same, prefer rooting higher in the callstack"?
Regardless, using a RootedTuple to collapse 3 roots into 1 in intl_CompareStrings seems worthwhile if it's going to be called this much.
| Assignee | ||
Comment 4•1 year ago
|
||
Hmm, strange. Searching for intl_CompareStrings gives me only two results about the JSString*, but not about the collator object:
Function '_ZN2js19intl_CompareStringsEP9JSContextjPN2JS5ValueE' has unnecessary root 'str1' of type JS::Rooted<JSString*> at js/src/builtin/intl/Collator.cpp:483
Function '_ZN2js19intl_CompareStringsEP9JSContextjPN2JS5ValueE' has unnecessary root 'str2' of type JS::Rooted<JSString*> at js/src/builtin/intl/Collator.cpp:483
| Assignee | ||
Comment 5•1 year ago
|
||
Rooting is unnecessary here according to hazard analysis.
Updated•1 year ago
|
Comment 6•1 year ago
|
||
(In reply to André Bargull [:anba] from comment #4)
Hmm, strange. Searching for
intl_CompareStringsgives me only two results about theJSString*, but not about the collator object:Function '_ZN2js19intl_CompareStringsEP9JSContextjPN2JS5ValueE' has unnecessary root 'str1' of type JS::Rooted<JSString*> at js/src/builtin/intl/Collator.cpp:483 Function '_ZN2js19intl_CompareStringsEP9JSContextjPN2JS5ValueE' has unnecessary root 'str2' of type JS::Rooted<JSString*> at js/src/builtin/intl/Collator.cpp:483
Oh. My analysis is probably wrong, then. Or rather, I think the hazard analysis is too conservative here: I'm guessing that the collator root is not reported as unnecessary because the Rooted<CollatorObject*> itself has a nontrivial destructor, so collator is considered live after GetOrCreateCollator returns. Which is ironic; collator needs a root because it creates the need for a root. Filed bug 1969062.
Comment 9•1 year ago
|
||
Interested to know if there are any performance changes here.
| Reporter | ||
Comment 10•1 year ago
|
||
Looks to be a pretty reasonable impact on my machine (~5% improvement)
matthew@ZenTower:~/perf/JetStream$ for i in `seq 0 10`; do ~/unified-git/obj-without-patch/dist/bin/js cli.js cdjs | grep Total; done;
Total Score: 89.564
Total Score: 89.013
Total Score: 90.707
Total Score: 90.670
Total Score: 90.366
Total Score: 88.864
Total Score: 90.516
Total Score: 90.488
Total Score: 90.581
Total Score: 89.759
Total Score: 90.734
matthew@ZenTower:~/perf/JetStream$ for i in `seq 0 10`; do ~/unified-git/obj-with-patch/dist/bin/js cli.js cdjs | grep Total; done;
Total Score: 95.864
Total Score: 95.374
Total Score: 93.020
Total Score: 95.809
Total Score: 94.058
Total Score: 95.250
Total Score: 94.506
Total Score: 96.505
Total Score: 95.108
Total Score: 96.371
Total Score: 94.626
Comment 11•1 year ago
|
||
Nice. That's a good improvement and shows this can be valuable.
Updated•1 year ago
|
Description
•