Make StyleElement::processStyleSheet() in a shadow tree faster |
||||||||
Issue descriptionThe context: https://crbug.com/699838 Given the trace [1] and the metrics which I have written locally, a StyleElement::processStyleSheet takes about 40% (= 60/149) in <x-thing>'s connected callbacks. The followings are total, not avg: - CE::connected_x-thing: - app1: 76.9ms - app2: 149.6ms - StyleElement::ProcessStyleSheet: - app1: 0.029ms - app2: 60.583ms - StyleElement::ProcessStyleSheet_under_x-thing: - app1: (empty) - app2: 60.556ms Some observations: - Blink does not parse the text contents of <style> element if it hits the cache. This behavior is working as expected. - However, even if we don't parse the text contents in processing each style element, the cost of processing stylesheet is still high enough. - StyleSheetContents::checkLoaded() is called every time in a processing stylesheet, and it takes 35.376 ms, which is more that 50% in StyleElement::ProcessStyleSheet() [1]: https://bugs.chromium.org/p/chromium/issues/detail?id=699838#c8
,
Apr 17 2017
,
Apr 17 2017
Hmm. Regarding checkLoaded, I have found that <style> element should fire a load event [1], and Blink actually fires a load event for each style element. That's sad. :( I am wondering who needs this event... [1] https://html.spec.whatwg.org/multipage/semantics.html#the-style-element > Once the attempts to obtain the style sheet's critical subresources, if any, are complete, or, if the style sheet has no critical subresources, once the style sheet has been parsed and processed, the user agent must, if the loads were successful or there were none, queue a task to fire an event named load at the style element, or, if one of the style sheet's critical subresources failed to completely load for any reason (e.g. DNS error, HTTP 404 response, a connection being prematurely closed, unsupported Content-Type), queue a task to fire an event named error at the style element. Non-network errors in processing the style sheet or its subresources (e.g. CSS parse errors, PNG decoding errors) are not failures for the purposes of this paragraph.
,
Apr 17 2017
I would say that some behaviors of <style> element are not good in Web Components era, where we have >1K custom element instances, and each shadow tree might have a <style> element inside of it. We do not want to queue a task to fire a load event for each. That looks too wasteful. I am thinking that we should make Constructable Stylesheet Objects [1] happen seriously. [1] http://tabatkins.github.io/specs/construct-stylesheets/
,
Apr 18 2017
Can I have a copy of your benchmark? I can work on the connected cost.
,
Apr 18 2017
,
Apr 18 2017
I have uploaded the current metrics I am using here: https://codereview.chromium.org/2760283002
,
Apr 18 2017
,
Apr 18 2017
,
Apr 20 2017
Regarding a load event, I have filed a bug 713562.
,
Sep 28 2017
,
Jan 31 2018
,
Aug 29
Releasing this bug. Maybe we might be in favor of Constructable Stylesheets. |
||||||||
►
Sign in to add a comment |
||||||||
Comment 1 by hayato@chromium.org
, Apr 17 2017