Opened 3 months ago

Closed 3 months ago

Last modified 2 months ago

#6967 closed change (fixed)

Hold on to only non-standard style sheets

Reported by: mjethani Assignee: mjethani
Priority: Unknown Milestone: Adblock-Plus-3.4-for-Chrome-Opera-Firefox
Module: Platform Keywords:
Cc: sebastian, kzar Blocked By:
Blocking: #7000 Platform: Unknown / Cross platform
Ready: no Confidential: no
Tester: Ross Verified working: yes
Review URL(s):

https://codereview.adblockplus.org/29885568/

Description (last modified by mjethani)

Background

Looking at the memory consumption of the extension, the total memory used by all strings with five tabs open (popular and heavy websites) is ~50 MB. Most of these strings are style sheets, which the extension holds on to so they can be updated. The style sheets are divided into "groups."

The groups are:

  • standard: the style sheet for normal element hiding
  • emulated: the style sheet for element hiding emulation
  • collapsing: the style sheet for element collapsing (when a video request is blocked and the <video> element needs to be hidden)

The extension keeps all these style sheets in memory per frame.

Of these, the standard group is updated only when the filter composer is opened and the user creates a new filter. The emulated group is no longer used (#6504), but may be used in the future. The collapsing group is potentially updated frequently as the content in the document changes.

The standard style sheet weights ~660 KB. If a tab contains ten frames, that's ~6.6 MB only in style sheets.

As noted above, the standard style sheet is updated only when the user opens the filter composer. Furthermore, when the standard style sheet needs to be updated, the old version of the style sheet must be removed and the new one must be added. The removal of style sheets is possible only on Firefox, as Chrome does not support tabs.removeCSS yet.

A lot of memory could be saved by holding on to only the non-standard style sheets for a document. It would also make the behavior consistent between Chrome and Firefox. In my tests, with Alexa Top 50 open in 50 tabs, the memory footprint goes from ~240 MB to ~120 MB with this change.

What to change

In lib/contentFiltering.js, add the style sheet to frame.injectedStyleSheets only if groupName is not "standard".

Change in behavior for users

Consider the following HTML document:

<p class="p1">One</p>
<p class="p2">Two</p>

Previously on Firefox, if you chose "Block element" from the popup menu and clicked on the first <p>, it would show you the filter ##.p1 as a suggestion. If you then added this filter, it would hide the first <p>. If you went to the options page and manually removed the filter, it would not unhide the first <p>. But ... if you then chose "Block element" again and added a filter for the second <p>: then it would unhide the first <p> and hide the second <p>.

On Chrome, the first <p> would remain hidden until you refreshed the page.

After this change, the behavior is the same on both Firefox and Chrome: if you want the first <p> to become visible, you have to refresh the page. In other words, any elements hidden via the "Block element" feature will remain hidden on both platforms until the document is reloaded.

At least for now, this is the correct behavior and should not be considered a bug.

Hints for testers

Simply test that element hiding filters are applying correctly to a document.

Change History (13)

comment:1 Changed 3 months ago by mjethani

  • Description modified (diff)
  • Owner set to mjethani
  • Summary changed from Save selectors instead of style sheet for each frame to Hold on to only non-standard style sheets

comment:2 Changed 3 months ago by mjethani

  • Description modified (diff)

comment:3 Changed 3 months ago by mjethani

  • Status changed from new to reviewing

comment:4 Changed 3 months ago by mjethani

  • Description modified (diff)

comment:5 Changed 3 months ago by mjethani

Regarding how I tested the patch, basically I closed all browser windows except Task Manager, reloaded the extension, and then ran this script:

#!/bin/bash
for domain in $(curl https://www.alexa.com/topsites | sed -nE 's/.*\/siteinfo\/([^"]*).*/\1/p')
do
  open -a 'Google Chrome' "http://$domain"
done
Last edited 3 months ago by mjethani (previous) (diff)

comment:6 Changed 3 months ago by abpbot

A commit referencing this issue has landed:
Issue 6967 - Hold on to only non-standard style sheets

comment:7 Changed 3 months ago by mjethani

  • Resolution set to fixed
  • Status changed from reviewing to closed

comment:8 Changed 3 months ago by mjethani

  • Milestone set to Adblock-Plus-3.4-for-Chrome-Opera-Firefox

comment:9 Changed 3 months ago by mjethani

  • Description modified (diff)

comment:10 Changed 3 months ago by mjethani

  • Description modified (diff)

comment:11 follow-up: Changed 3 months ago by Ross

  • Tester changed from Unknown to Ross
  • Verified working set

Done. Element hiding still works as expected and there is a measureable drop in memory usage. Memory usage for the extension in Chrome 69 for example drops from ~170MB (last release) to ~104MB (latest devbuild) with the first 25 sites of Alexa opened.

ABP 3.3.2.2143
Chrome 69 / 49 / Windows 10
Firefox 62 / 51 / Windows 10
Opera 56 / 36 / Windows 10

comment:12 in reply to: ↑ 11 Changed 3 months ago by mjethani

Replying to Ross:

Memory usage for the extension in Chrome 69 for example drops from ~170MB (last release) to ~104MB (latest devbuild) with the first 25 sites of Alexa opened.

Incredible, thanks!

comment:13 Changed 2 months ago by mjethani

  • Blocking 7000 added
Note: See TracTickets for help on using tickets.