Commit d91c88b2 authored by Alex Rudenko's avatar Alex Rudenko Committed by Commit Bot

Skip diffing algorithm for constructed stylesheets

If a constructed stylesheet contains rules with 'background-clip:text;',
InspectorStyleSheet won't be able to parse them properly, causing
the rule diffing algorithm to run. When the number of rules to diff
is high, it causes performance problems when opening DevTools.
This CL skips the diffing for constructed stylesheets, because the
order of rules for constructed stylesheets is known. Ultimately, this
workaround would not be needed when InspectorStyleSheet can parse the
CSS rules properly. See crbug.com/1132778, crbug.com/604023.

Fixed: 1131113
Change-Id: I5c38a52bfb2b04334530c292cd8b4e15c9f6c2f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2435304Reviewed-by: default avatarPeter Marshall <petermarshall@chromium.org>
Reviewed-by: default avatarMathias Bynens <mathias@chromium.org>
Commit-Queue: Alex Rudenko <alexrudenko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811634}
parent ff0d5a18
...@@ -1900,6 +1900,24 @@ void InspectorStyleSheet::MapSourceDataToCSSOM() { ...@@ -1900,6 +1900,24 @@ void InspectorStyleSheet::MapSourceDataToCSSOM() {
CSSRuleVector& parsed_rules = parsed_flat_rules_; CSSRuleVector& parsed_rules = parsed_flat_rules_;
if (page_style_sheet_->IsConstructed()) {
// If we are dealing with constructed stylesheets, the order
// of the parsed_rules matches the order of cssom_rules
// because the source CSS is generated based on CSSOM rules
// in the same order.
// Therefore, we can skip the expensive diff algorithm below
// that causes performance issues if there are subtle differences
// in rules due to specific issues with the CSS parser.
// See crbug.com/1131113, crbug.com/604023, crbug.com/1132778.
DCHECK(parsed_rules.size() == cssom_rules.size());
auto min_size = std::min(parsed_rules.size(), cssom_rules.size());
for (wtf_size_t i = 0; i < min_size; ++i) {
rule_to_source_data_.Set(i, i);
source_data_to_rule_.Set(i, i);
}
return;
}
Vector<String> cssom_rules_text = Vector<String>(); Vector<String> cssom_rules_text = Vector<String>();
Vector<String> parsed_rules_text = Vector<String>(); Vector<String> parsed_rules_text = Vector<String>();
for (wtf_size_t i = 0; i < cssom_rules.size(); ++i) for (wtf_size_t i = 0; i < cssom_rules.size(); ++i)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment