Make style-utils.js getRuleText faster
Categories
(DevTools :: Inspector, task)
Tracking
(firefox125 wontfix, firefox126 fixed)
People
(Reporter: nchevobbe, Assigned: nchevobbe)
References
(Blocks 2 open bugs)
Details
Attachments
(2 files, 2 obsolete files)
The function uses the lexer to find the rule "body" text, i.e. the content between opening and closing curly brackets, which can be slow on big stylesheets (see https://bugzilla.mozilla.org/show_bug.cgi?id=1644138#c12).
We can probably move this specific part to InspectorUtils
and parse the text in Rust with cssparser which could be faster
function getRuleText(initialText, line, column) {
if (typeof line === "undefined" || typeof column === "undefined") {
throw new Error("Location information is missing");
}
const { offset: textOffset, text } = getTextAtLineColumn(
initialText,
line,
column
);
const lexer = getCSSLexer(text);
// Search forward for the opening brace.
while (true) {
const token = lexer.nextToken();
if (!token) {
throw new Error("couldn't find start of the rule");
}
if (token.tokenType === "symbol" && token.text === "{") {
break;
}
}
// Now collect text until we see the matching close brace.
let braceDepth = 1;
let startOffset, endOffset;
while (true) {
const token = lexer.nextToken();
if (!token) {
break;
}
if (startOffset === undefined) {
startOffset = token.startOffset;
}
if (token.tokenType === "symbol") {
if (token.text === "{") {
++braceDepth;
} else if (token.text === "}") {
--braceDepth;
if (braceDepth == 0) {
break;
}
}
}
endOffset = token.endOffset;
}
// If the rule was of the form "selector {" with no closing brace
// and no properties, just return an empty string.
if (startOffset === undefined) {
return { offset: 0, text: "" };
}
// If the input didn't have any tokens between the braces (e.g.,
// "div {}"), then the endOffset won't have been set yet; so account
// for that here.
if (endOffset === undefined) {
endOffset = startOffset;
}
// Note that this approach will preserve comments, despite the fact
// that cssTokenizer skips them.
return {
offset: textOffset + startOffset,
text: text.substring(startOffset, endOffset),
};
}
Assignee | ||
Comment 1•11 months ago
|
||
Updated•11 months ago
|
Assignee | ||
Comment 2•11 months ago
|
||
Comment 4•11 months ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/e6c06c8b6ecd
https://hg.mozilla.org/mozilla-central/rev/db1073373385
https://hg.mozilla.org/mozilla-central/rev/5b0da4101568
Assignee | ||
Comment 5•10 months ago
|
||
== Change summary for alert #41682 (as of Thu, 07 Mar 2024 04:35:46 GMT) ==
Improvements:
Ratio | Test | Platform | Options | Absolute values (old vs new) |
---|---|---|---|---|
10% | damp custom.inspector.manycssvariables.selectnode | linux1804-64-shippable-qr | e10s fission stylo webrender-sw | 265.57 -> 239.60 |
8% | damp custom.inspector.manyrules.selectnode | linux1804-64-shippable-qr | e10s fission stylo webrender | 572.08 -> 525.49 |
8% | damp custom.inspector.manyrules.selectnode | linux1804-64-shippable-qr | e10s fission stylo webrender-sw | 558.64 -> 513.76 |
7% | damp browser-toolbox.webconsole-ready.DAMP | linux1804-64-shippable-qr | e10s fission stylo webrender-sw | 681.83 -> 633.57 |
7% | damp custom.inspector.manyrules.selectnode | windows10-64-shippable-qr | e10s fission stylo webrender | 494.34 -> 460.01 |
... | ... | ... | ... | ... |
5% | damp custom.inspector.manycssvariables.selectnode | windows10-64-shippable-qr | e10s fission stylo webrender | 227.19 -> 216.65 |
For up to date results, see: https://treeherder.mozilla.org/perfherder/alerts?id=41682
Assignee | ||
Comment 6•10 months ago
|
||
Bug 1884230 reverted this change
Assignee | ||
Comment 7•10 months ago
|
||
The next patch modifies getRuleText
so it only returns the text, and no
longer the offset at which the rule starts.
The only consumre of the returned offset was in StyleRuleActor#setRuleText
,
so we migrate this directly to a InspectorUtils method to avoid mixing JS string
indeces with Rust bytes position.
Assignee | ||
Comment 8•10 months ago
|
||
InspectorUtils.getRuleBodyTextOffset
was returning bytes position, and we
were using them directly in Javascript substring
, which causes problem
with non-ascii chars.
Instead of returning offsets to compute the rule string, we directly return
the string from InspectorUtils which is easier to work with.
Updated•10 months ago
|
Updated•10 months ago
|
Updated•10 months ago
|
Updated•9 months ago
|
Assignee | ||
Updated•9 months ago
|
Assignee | ||
Updated•9 months ago
|
Comment 10•9 months ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/c374d883ed01
https://hg.mozilla.org/mozilla-central/rev/f6ffb60aead6
Updated•9 months ago
|
Assignee | ||
Comment 11•9 months ago
|
||
Perfherder has detected a devtools performance change from push 1b56c653a5ee3a14ec0955b092498999e9333bfa.
Improvements:
Ratio | Test | Platform | Options | Absolute values (old vs new) |
---|---|---|---|---|
9% | damp custom.inspector.manyrules.selectnode | linux1804-64-shippable-qr | e10s fission stylo webrender | 763.88 -> 691.86 |
8% | damp custom.inspector.manyrules.selectnode | windows10-64-shippable-qr | e10s fission stylo webrender-sw | 639.42 -> 585.51 |
8% | damp custom.inspector.manyrules.selectnode | windows10-64-shippable-qr | e10s fission stylo webrender | 637.11 -> 586.82 |
Details of the alert can be found in the alert summary, including links to graphs and comparisons for each of the affected tests.
If you need the profiling jobs you can trigger them yourself from treeherder job view or ask a sheriff to do that for you.
You can run these tests on try with ./mach try perf --alert 42216
For more information on performance sheriffing please see our FAQ.
Description
•