Skip to content

[Perf] CPU regression caused by adblock unified catalog #35922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
atuchin-m opened this issue Feb 9, 2024 · 9 comments · Fixed by brave/brave-core#22082 · May be fixed by brave/brave-core#22049
Closed

[Perf] CPU regression caused by adblock unified catalog #35922

atuchin-m opened this issue Feb 9, 2024 · 9 comments · Fixed by brave/brave-core#22082 · May be fixed by brave/brave-core#22049

Comments

@atuchin-m
Copy link
Contributor

We have a slight CPU usage spike on some platforms (mac-m1, win11) in the revision range brave/brave-core@v1.64.35...v1.64.36
image

I believe it’s the adblock changes: brave/brave-core#21556
I’ve checked adblock work in the traces before/after, the structure is changed and the new number are bigger:

Before 890ms
After: 1085ms 

image

@atuchin-m atuchin-m added perf OS/Android Fixes related to Android browser functionality OS/Desktop perf-regression An perf browser issue by the perf dashboard labels Feb 9, 2024
@antonok-edm
Copy link
Collaborator

As far as I'm aware, we have the following options for resolving this:

  1. preload cached resources at launch followed by lazier list updates later
  2. bundle lists (or a DAT) with browser builds
  3. batch list updates together so they don't trigger update races

However:

  • (3) will make things worse without (2), because any slow-loading lists would prevent shields from working for a long time at startup.
  • (2) will not improve the measurements much without (1), because the list updates will still occur at startup.
  • (1) by itself does not affect first launch, which is what the perf measurements above are for.

@ShivanKaul
Copy link
Collaborator

@atuchin-m is the spike in CPU usage on some platforms only on first launch?

@atuchin-m
Copy link
Contributor Author

From the slack thread:
With 2 default extra lists (easy list cookies + mobile notifications) there is noticeable difference.
before (393ms)/after(287+306=593ms) [win-10, local Static build on 1.64.55 with/without reverted PR]
image
image

@atuchin-m
Copy link
Contributor Author

atuchin-m commented Feb 12, 2024

Hm, I’ve enabled 10 extra lists.
556ms vs 2900ms 😱
More than 5x slower..
I’ve double checked this, but I still hope I’m doing something wrong with my measurement.
One of the different I see is that we start to call from_filter_set more often (checked in the debugger 6 vs 10+ times) and with large set(the first arg).
@antonok-edm could you add some counters and check how many rules we process before/after the change?
image
image
image
image

@kjozwiak
Copy link
Member

The above requires 1.64.104 or higher for 1.64.x verification 👍 @brave/qa-team please take a look at https://bravesoftware.slack.com/archives/CHGKGMHDJ/p1710309453936669?thread_ts=1709255617.117759&cid=CHGKGMHDJ re: the plan for this one. Quick summary:

Created #36749 which is also happening via 1.63.x

@stephendonner
Copy link

stephendonner commented Mar 14, 2024

Verified PASSED using

Brave	1.64.104 Chromium: 123.0.6312.46 (Official Build) (x86_64) 
Revision	0ca3d372cf8aab96fafdd75f5c5c8d2012bc0cc6
OS	macOS Version 11.7.10 (Build 20G1427)

NOTE: this is still happening if you load certain sites quickly enough, as in #36749 (in which I commented)

Also reproduces in

Brave	1.63.174 Chromium: 122.0.6261.128 (Official Build) (x86_64) 
Revision	0d369d4e1dfee7bcea82774079dc8cd658746c98
OS	macOS Version 11.7.10 (Build 20G1427) 

so not a regression

YouTube

initial load reload
Screen Shot 2024-03-14 at 11 06 41 AM Screen Shot 2024-03-14 at 11 06 53 AM

AOL

initial load reload
Screen Shot 2024-03-14 at 3 49 34 PM Screen Shot 2024-03-14 at 11 12 30 AM

TMZ

Screen Shot 2024-03-14 at 11 10 19 AM

SFGate

Screen Shot 2024-03-14 at 11 14 00 AM

@kjozwiak
Copy link
Member

Quick Note: For each of the cases mentioned below, the following was done in terms of STR/Cases:

  • ensured that https://www.youtube.com/watch?v=OJ56MAGFPGM was already copied/ready to paste into URL bar
  • ensured that all profiles have been removed (basically ensuring you're launching using a clean profile)
  • launched Brave and then quickly pasted https://www.youtube.com/watch?v=OJ56MAGFPGM (as quickly as possible)

If an issue was found/ads initially being displayed, compared against 1.63.169 Chromium: 122.0.6261.111 and ensured that it wasn't any worse with the above PR. Basically ensuring it was also happening via the current release build.

Win 10 x64 verifications using a VM (slowing down VM & Network)

Verification PASSED on Win 10 x64 VM using the following build(s):

Brave | 1.64.104 Chromium: 123.0.6312.46 (Official Build) (64-bit)
-- | --
Revision | 0ca3d372cf8aab96fafdd75f5c5c8d2012bc0cc6
OS | Windows 10 Version 22H2 (Build 19045.3803)

Test Case #1 - Slowing down VM via RAM & CPU - No ads appearing on initial launch

  • set the RAM of the current VM to 4GB
  • assigned 2 CPU's to the VM from host (ensured that Dynamic Memory is also disabled)
Example Example
image image
RAMCPU.mp4

Test Case #2 - Slowing down VM via CPU, RAM & Network (200ms delay) - No ads appearing on initial launch

  • set the RAM of the current VM to 4GB
  • assigned 2 CPU's to the VM from host (ensured that Dynamic Memory is also disabled)
  • using https://jagt.github.io/clumsy/index.html to slow down the VM network (using 200ms delay)
200msDelay.mp4

Test Case #3 - Slowing down VM via CPU, RAM & Network (300ms delay) - No ads appearing on initial launch

  • set the RAM of the current VM to 4GB
  • assigned 2 CPU's to the VM from host (ensured that Dynamic Memory is also disabled)
  • using https://jagt.github.io/clumsy/index.html to slow down the VM network (using 300ms delay)
300msDelay.mp4

Win 11 x64 verifications using a real desktop/high-end HW specs

Brave | 1.64.104 Chromium: 123.0.6312.46 (Official Build) (64-bit)
-- | --
Revision | 0ca3d372cf8aab96fafdd75f5c5c8d2012bc0cc6
OS | Windows 11 Version 23H2 (Build 22631.3296)

Test Case #4 - Desktop with high-end HW specs - No ads appearing on initial launch

The following is the basic check re: loading a website right after Brave launches on a machine with high-end HW specs.

highHWSpecs.mp4

@kjozwiak
Copy link
Member

kjozwiak commented Mar 14, 2024

Quick Note: For each of the cases mentioned below, the following was done in terms of STR/Cases:

  • ensured that https://www.youtube.com/watch?v=OJ56MAGFPGM was already copied/ready to paste into URL bar
  • ensured that all profiles have been removed (basically ensuring you're launching using a clean profile)
  • launched Brave and then quickly pasted https://www.youtube.com/watch?v=OJ56MAGFPGM (as quickly as possible)

If an issue was found/ads initially being displayed, compared against 1.63.169 Chromium: 122.0.6261.111 and ensured that it wasn't any worse with the above PR. Basically ensuring it was also happening via the current release build.

Pixel 6 running Android 14 verifications throttling network

Verification PASSED on Pixel 6 running Android 14 using the following build(s):

Brave | 1.64.104 Chromium: 123.0.6312.46 (Official Build) (64-bit)
--- | --
Revision | 0ca3d372cf8aab96fafdd75f5c5c8d2012bc0cc6
OS  | Android 14; Build/AP21.240119.009; 34; REL

Some quick notes/caveats:

  • I originally tried throttling the network to 128kbps, 256kbps & 1Mbps but it was impossible to load any website/content
  • Because you need to run through several onboarding screens, the Android test is not as instant as the Desktop
    • the components/lists most likely downloaded/applied by the time you went through the onboarding screens

Test Case #1 - No network throttling (base user case) - No ads appearing on initial launch

Video of verification(s) --> https://youtu.be/xjJusg90i-I

Test Case #2 - Throttling network at 5MBps - No ads appearing on initial launch

Using the Network download rate limit feature via the Developer Option, I throttled the phones network to 5Mbps and then went through the same STR/Cases mentioned above re: loading a website right after the application has launched.

Video of verification(s) --> https://youtu.be/vRnLyxVrp6Q

Test Case #3 - Throttling network at 1MBps - No ads appearing on initial launch

Using the Network download rate limit feature via the Developer Option, I throttled the phones network to 1Mbps and then went through the same STR/Cases mentioned above re: loading a website right after the application has launched. Even though the website barely loaded, the YT video started without any ads.

Video of verification(s) --> https://youtu.be/-15kWVtJhfQ

Samsung Galaxy Tab S8 Ultra running Android 14 verifications throttling network

Verification PASSED on Samsung Galaxy Tab S8 Ultra running Android 14 using the following build(s):

Brave | 1.64.104 Chromium: 123.0.6312.46 (Official Build) (64-bit)
--- | ---
Revision | 0ca3d372cf8aab96fafdd75f5c5c8d2012bc0cc6
OS | Android 14; Build/UP1A.231005.007; 34; REL

Some quick notes/caveats:

  • I originally tried throttling the network to 128kbps, 256kbps & 1Mbps but it was impossible to load any website/content
  • Because you need to run through several onboarding screens, the Android test is not as instant as the Desktop
    • the components/lists most likely downloaded/applied by the time you went through the onboarding screens

Test Case #1 - No network throttling (base user case) - No ads appearing on initial launch

Screen_Recording_20240314_225232_Brave.mp4

Test Case #2 - Throttling network at 5MBps - No ads appearing on initial launch

Using the Network download rate limit feature via the Developer Option, I throttled the phones network to 5Mbps and then went through the same STR/Cases mentioned above re: loading a website right after the application has launched.

Screen_Recording_20240314_223932_Brave.mp4

Test Case #3 - Throttling network at 1MBps - No ads appearing on initial launch

Using the Network download rate limit feature via the Developer Option, I throttled the phones network to 1Mbps and then went through the same STR/Cases mentioned above re: loading a website right after the application has launched. Even though the website barely loaded, the YT video started without any ads.

Screen_Recording_20240314_224756_Brave.mp4

@MadhaviSeelam
Copy link

MadhaviSeelam commented Mar 15, 2024

Verification PASSED using

Brave	1.64.104 Chromium: 123.0.6312.46 (Official Build) (64-bit) 
Revision	0ca3d372cf8aab96fafdd75f5c5c8d2012bc0cc6
OS	Linux

Encountered #36749

Verified on following sites as a basic check with loading a website right after Brave launches.
Conformed No ads appearing on initial launch

Youtube:

2024-03-15_12h49_56.mp4

Dailymotion:

2024-03-15_12h56_30.mp4

USA today:

2024-03-15_12h59_27.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment