CompatibilityActor#getNodeCssIssues could be faster
Categories
(DevTools :: Inspector: Compatibility, defect, P3)
Tracking
(firefox142 fixed)
| Tracking | Status | |
|---|---|---|
| firefox142 | --- | fixed |
People
(Reporter: nchevobbe, Assigned: nchevobbe)
References
(Blocks 1 open bug)
Details
Attachments
(1 file)
The function is defined in https://searchfox.org/mozilla-central/rev/38e462fe13ea42ae6cc391fb36e8b9e82e842b00/devtools/server/actors/compatibility/compatibility.js#124-159
async getNodeCssIssues(node, targetBrowsers) {
const pageStyle = await this.inspector.getPageStyle();
const styles = await pageStyle.getApplied(node, {
skipPseudo: false,
});
const declarationBlocks = styles.entries
.map(({ rule }) => {
// Replace form() with a function to get minimal subset
// of declarations from StyleRuleActor when such a
// function lands in the StyleRuleActor
const declarations = rule.form().declarations;
if (!declarations) {
return null;
}
return declarations.filter(d => !d.commentOffsets);
})
.filter(declarations => declarations && declarations.length);
return declarationBlocks
.map(declarationBlock =>
mdnCompatibility.getCSSDeclarationBlockIssues(
declarationBlock,
targetBrowsers
)
)
.flat()
.reduce((issues, issue) => {
// Get rid of duplicate issue
return issues.find(
i => i.type === issue.type && i.property === issue.property
)
? issues
: [...issues, issue];
}, []);
}
There are a few things that could be better:
- we're creating a lot of intermediary arrays (mapping, filtering, reducing, …)
- we're calling
getCSSDeclarationBlockIssuesfor each matching rules, although we could build an array of declarations and only call it once - we're filtering duplicated issues, but we could avoid having them in the first place by only pass one decoration per property name (since we're only checking the property name for compatibility issues)
- we're using
StyleActor#formjust to get the declarations, but there's overhead as it computed other data we won't use - the declarations we're getting for the form also include the one in comments, which we then filter out (checking
commentOffsets)
| Assignee | ||
Comment 1•8 months ago
|
||
The function was building multiple arrays to return a list of issues, which could
be costly.
We're now only build a list of declarations that we pass only once to getCSSDeclarationBlockIssues.
Since we're only checking the compatibility based on the property name, we don't
add declarations if we already added one in the array previously (instead of filtering
the list afterward to remove duplicated issues, like we were doing before).
Finally we extract a StyleRuleActor#parseRuleDeclarations method from what was
previously done in the StyleRuleActor form, and call that directly from getNodeCssIssues,
so we don't pay the cost for other data being computed in the form method, which
we wouldn't need here.
Updated•8 months ago
|
Updated•8 months ago
|
Comment 3•8 months ago
|
||
| bugherder | ||
Updated•8 months ago
|
Description
•