|author||Daniel Silverstone <email@example.com>||2017-02-04 09:41:13 +0000|
|committer||Daniel Silverstone <firstname.lastname@example.org>||2017-02-04 09:41:13 +0000|
Initial conversion from MediaWiki, 20170204
Diffstat (limited to 'libcss_style_sharing.mdwn')
1 files changed, 48 insertions, 0 deletions
diff --git a/libcss_style_sharing.mdwn b/libcss_style_sharing.mdwn
new file mode 100644
@@ -0,0 +1,48 @@
+[[!meta title="LibCSS Style Sharing"]]
+[[!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
+ - 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.