Currently WebKit does not cache the parsed results from included external CSS files. The operation of parsing all included CSS files is quite expensive, and for some popular websites (ex: youtube), the cumulative time taken to parse all external CSS files can be upto a few percentage points (ex: for youtube, it incurs around 3 ~ 7 %, many other websites also incur a few % points) of pageload time. By keeping the parsed results in cache, and re-using them for future requests (ex: another URL from youtube.com domain), we can reduce the time taken for pageload. (Patch to follow) Here is some data for Youtube domain urls: (Based on GTK build of WebKit nightly r93508 on Ubuntu), numbers averaged over 10 iterations (run on the same day) Visited URL CSS URL 1. http://www.youtube.com/ - PageLoad time: 1952 , Pageload time when caching enabled: 2261 http://s.ytimg.com/yt/cssbin/www-core-vflT2SXA2.css - ParseTime: 47.87, parse time with caching: 40.915967 Parse time as % of pageload 2.4523565574, with caching: 1.80 2. http://www.youtube.com/music - PageLoad time:1685 , pageload time with caching: 1278 http://s.ytimg.com/yt/cssbin/www-core-vflT2SXA2.css - Parsetime: 37.13, with caching: 0.63 http://s.ytimg.com/yt/cssbin/www-the-rest-vflNb6rAI.css - ParseTime: 3, with caching: 1.12 http://s.ytimg.com/yt/cssbin/www-browse-new-vfl89j8Ia.css - ParseTime: 17.07, with caching: 6.4 Cumulative parsing time: 57.2, with caching: 8.17 Parse time as % of pageload 3.3946587537, with caching: 0.63 3. http://www.youtube.com/shows - PageLoad time: 1287 , pageload time with caching: 1390 http://s.ytimg.com/yt/cssbin/www-core-vflT2SXA2.css - ParseTime: 22.08, with caching: 0.19 http://s.ytimg.com/yt/cssbin/www-the-rest-vflNb6rAI.css - ParseTime: 1.04, with caching: 0.02 http://s.ytimg.com/yt/cssbin/www-browse-new-vfl89j8Ia.css - ParseTime: 4.7, with caching: 0.21 Cumulative parsing time: 27.82, with caching: 0.43 Parse time as % of pageload 2.1616161616, with caching: 0.03 4. http://www.youtube.com/shows/entertainment?feature=sh_c&pt=g&l=en - PageLoad time: 618, PLT with caching: 475 http://s.ytimg.com/yt/cssbin/www-core-vflT2SXA2.css - ParseTime: 31.96, with caching: 0.17 http://s.ytimg.com/yt/cssbin/www-the-rest-vflNb6rAI.css - ParseTime: 0.96, with caching: 0.01 http://s.ytimg.com/yt/cssbin/www-browse-new-vfl89j8Ia.css - ParseTime: 5.29, with caching: 0.04 Cumulative parsing time: 38.21, with caching: 0.23 Parse time as % of pageload 6.1828478964, with caching: 0.04 http://www.youtube.com/shows/news?feature=sh_c&pt=g&l=en - PageLoad time: 607 , with caching: 921 http://s.ytimg.com/yt/cssbin/www-core-vflT2SXA2.css - ParseTime: 31.8, with caching: 0.33 http://s.ytimg.com/yt/cssbin/www-the-rest-vflNb6rAI.css - ParseTime: 1.04, with caching: 0.01 http://s.ytimg.com/yt/cssbin/www-browse-vflXj985o.css - ParseTime: 4.3, with caching: 7.85 Cumulative parsing time: 37.14, with caching: 8.2 Parse time as % of pageload 6.118616145, with caching: 0.89 http://www.youtube.com/trailers - PageLoad time: 856, PLT with caching: 919 http://s.ytimg.com/yt/cssbin/www-core-vflT2SXA2.css - ParseTime: 44.11, with caching: 0.49 http://s.ytimg.com/yt/cssbin/www-the-rest-vflNb6rAI.css - ParseTime: 1.53, with caching: 0.04 http://s.ytimg.com/yt/cssbin/www-browse-new-vfl89j8Ia.css - ParseTime: 9.38, with caching: 0.1 Cumulative parsing time: 55.02, with caching: 0.64 Parse time as % of pageload 6.4275700935, with caching: 0.07 http://www.youtube.com/live PageLoad time: 875, PLT with caching: 774 http://s.ytimg.com/yt/cssbin/www-core-vflT2SXA2.css - ParseTime: 21.34, with caching: 0.25 http://s.ytimg.com/yt/cssbin/www-the-rest-vflNb6rAI.css - ParseTime: 0.82, with caching: 0.02 http://s.ytimg.com/yt/cssbin/www-browse-vflXj985o.css - ParseTime: 4.92, with caching: 0.05 Cumulative parsing time: 27.08, with caching: 0.32 Parse as % of pageload 1.387295082, with cacing: 0.04
Created attachment 105125 [details] Patch to enable caching parsed results from external CSS files. First patch to enable caching parsed results from external CSS files (Bug: 66904) Looking forward to comments from reviewers. Swaroop Kalsaapur
While the idea of caching parsed stylesheets is right this patch can't work correctly. CSSRules have a parent, they can't be shared between different stylesheets or document. Parsed stylesheets eat significant amount of memory, any patch of this nature has to implement memory management for them too (computing decodedSize, purging).
Agree on the necessity to compute the decoded size, and purging the decoded data. The current patch does not account for the decoded data, yet. But, it does cache the parsed results and shows gain in terms of time. How do I go about getting the decoded size? Are there APIs available to gather the size information? or do I need to traverse the entire CSSRuleSet object, collecting individual sizes? Any pointers will help. Thanks
Attachment 105125 [details] did not pass style-queue: Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/WebCore/ChangeLog', u'Source/WebCor..." exit_code: 1 Source/WebCore/ChangeLog:1: ChangeLog entry has no bug number [changelog/bugnumber] [5] Total errors found: 1 in 12 files If any of these errors are false positives, please file a bug against check-webkit-style.
Comment on attachment 105125 [details] Patch to enable caching parsed results from external CSS files. Attachment 105125 [details] did not pass chromium-ews (chromium-xvfb): Output: http://queues.webkit.org/results/9570378 New failing tests: http/tests/security/cross-origin-css.html http/tests/inspector/network/network-initiator.html
This code has been significantly refactored since this patch was proposed. There doesn't seem to be any action we can take here.