Changes between Version 3 and Version 4 of Ticket #7045


Ignore:
Timestamp:
10/15/2018 05:23:17 AM (14 months ago)
Author:
mjethani
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #7045 – Description

    v3 v4  
    11=== Background === 
    2 In EasyList+AA there are about 150 element hiding filters and exceptions of lengths exceeding 1,000 characters. Of these, about 20 are longer than 100,000 characters. Similarly, there are about 600 blocking and whitelist filters of lengths exceeding 1,000 characters, of which about 10 are longer than 100,000 characters. Most of the filter text is the list of domains, and this list is repeated often. 
     2In EasyList+AA there are about '''150 element hiding filters and exceptions''' of lengths '''exceeding 1,000 characters'''. Of these, about 20 are longer than 100,000 characters. Similarly, there are about '''600 blocking and whitelist filters''' of lengths '''exceeding 1,000 characters''', of which about 10 are longer than 100,000 characters. Most of the filter text is the '''list of domains''', and this list is '''repeated often'''. 
    33 
    4 The memory layout of this text can be optimized by restructuring it in the following manner: 
     4The '''memory layout''' of this text can be optimized by '''restructuring''' it in the following manner: 
    55 
    66* Suppose there are two filters `example.com#@#selector1` and `example.com#@#selector2` occupying a total of 46 bytes 
     
    99* Next, we create two new ''concatenated'' strings `example.com` plus `#@#selector1` and `example.com` plus `#@#selector2` occupying a total of 35 bytes (11 plus 12 plus 12) 
    1010 
    11 In order for this to work on V8, we would have to override some of V8's own string optimizations that are sometimes harmful (V8 issue [https://bugs.chromium.org/p/v8/issues/detail?id=2869 #2869]). When we "slice" out a part of a string, we must properly separate it from its V8 internal parent string, using an operation like `JSON.parse(JSON.stringify(string))`. Once we are able to do this, we can restructure such long filter texts with a more efficient layout in memory. 
     11In order for this to work on V8, we would have to '''override some of V8's own string optimizations''' that are sometimes harmful (V8 issue [https://bugs.chromium.org/p/v8/issues/detail?id=2869 #2869]). When we "slice" out a part of a string, we must properly separate it from its V8 internal parent string, using an operation like `JSON.parse(JSON.stringify(string))`. Once we are able to do this, we can restructure such long filter texts with a more efficient layout in memory. 
    1212 
    13 I have written a [https://codereview.adblockplus.org/29909576/ patch] that performs this optimization on filters where the domains part of the text is 1,000 characters or longer. It reduces the initial heap used by ~3.8 MB, from ~39.6 MB to ~35.8 MB. More pertinently, it reduces the memory occupied by all strings from ~16 MB down to ~12 MB. 
     13I have written a [https://codereview.adblockplus.org/29909576/ patch] that performs this optimization on filters where the domains part of the text is 1,000 characters or longer. It '''reduces the initial heap used''' by ~3.8 MB, '''from ~39.6 MB to ~35.8 MB'''. More pertinently, it reduces the memory occupied by all strings from ~16 MB down to ~12 MB. 
    1414 
    1515=== What to change ===