From e7366bf41f68cfe07e9ea03fc4a398baecbae651 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 4 Feb 2017 09:41:13 +0000 Subject: Initial conversion from MediaWiki, 20170204 --- libcss_style_sharing.mdwn | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 libcss_style_sharing.mdwn (limited to 'libcss_style_sharing.mdwn') diff --git a/libcss_style_sharing.mdwn b/libcss_style_sharing.mdwn new file mode 100644 index 0000000..1c8a635 --- /dev/null +++ b/libcss_style_sharing.mdwn @@ -0,0 +1,48 @@ +[[!meta title="LibCSS Style Sharing"]] +[[!meta author="Tlsa"]] +[[!meta date="2014-01-03T15:21:20Z"]] + + +[[!toc]] At the moment NetSurf does +not share computed styles. Every element on every page has its own +unique computed style allocated. Computed styles are quite large. +Consider the following page: + +- + +It has over twenty thousand element nodes each with its own computed +style. But there are less than 40 unique computed styles on the page. +This is a massive waste of memory. + +Computed Style Sharing +---------------------- + +If different elements can reference the same computed styles, we can +save a lot of memory. + +- Computed styles will become reference counted. +- There are two ways to go about sharing computed styles: + 1. Memoising calls to css\_get\_style() + - We'll use selection calbacks to find if node has previous + sibling with same element name, classes, etc. If so the + style for node can be an extra reference to the computed + style of the previous sibling. + - Presentational hint gathering for nodes needs to change such + that presentational hints for two nodes can be compared. + - Only shares styles between siblings. Could be extended to + share between cousins, etc. + - As well as saving memory, this will make selection faster. + - It will be a big saving in cases where styles can be + shared, by bypassing the need to iterate over the + applicable selector chains. + - In cases where the styles can't be shared, it will have + a relatively small cost. + + 2. Interning computed styles + - Will have a performance cost. + - Much greater scope for sharing computed styles than the + above. + - Can even share computed styles between different pages. + (NetSurf will be unique in doing that.) + - Fully compatible with the above, so we can do both. + -- cgit v1.2.3