Optimize stylesheet insertions
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Sep 2012 14:52:19 +0000 (14:52 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Sep 2012 14:52:19 +0000 (14:52 +0000)
commit0517bdff226da97950ce117bd64738f050c1773b
treea519b3568148a1875fc8f19d9a7981011208499b
parent33d2a5f38d4e304a487c6091161b6c6409e71c5e
Optimize stylesheet insertions
https://bugs.webkit.org/show_bug.cgi?id=97627

Reviewed by Andreas Kling.

PerformanceTests:

Add synthetic performance test for avoiding style recalcs on stylesheet inserts.

* CSS/StyleSheetInsert.html: Added.

Source/WebCore:

We currently do scope analysis for stylesheets that are added to the end of the active stylesheet list to avoid unnecessary style
recalcs and StyleResolver rebuilding. However it is somewhat common to insert <style> elements dynamically to positions other than last.
In this case we currently simply force full style recalc. We should do scope analysis and partial style recalcs also in these cases.

PerformanceTests/CSS/StyleSheetInsert.html microbenchmark shows ~20x progression from the patch.

* css/StyleResolver.cpp:
(WebCore::StyleResolver::StyleResolver):
(WebCore::StyleResolver::resetAuthorStyle):

    Add a way to reset author RuleSet without deleting the whole StyleResolver.

(WebCore):
* css/StyleResolver.h:
(StyleResolver):
* dom/DocumentStyleSheetCollection.cpp:
(WebCore::DocumentStyleSheetCollection::analyzeStyleSheetChange):

    Check if there have been insertions to the stylesheet list. If so we need to reset
    the StyleResolver (to handle rule position changes) but don't need to force full
    style recalc. Do scope analysis for inserted stylesheets as well.

(WebCore::DocumentStyleSheetCollection::updateActiveStyleSheets):
* dom/DocumentStyleSheetCollection.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@129644 268f45cc-cd09-0410-ab3c-d52691b4dbfc
PerformanceTests/CSS/StyleSheetInsert.html [new file with mode: 0644]
PerformanceTests/ChangeLog
Source/WebCore/ChangeLog
Source/WebCore/css/StyleResolver.cpp
Source/WebCore/css/StyleResolver.h
Source/WebCore/dom/DocumentStyleSheetCollection.cpp
Source/WebCore/dom/DocumentStyleSheetCollection.h