Skip to content
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

Optimize parseDomain in content_cosmetic.ts #17906

Closed
atuchin-m opened this issue Sep 7, 2021 · 6 comments · Fixed by brave/brave-core#10038
Closed

Optimize parseDomain in content_cosmetic.ts #17906

atuchin-m opened this issue Sep 7, 2021 · 6 comments · Fixed by brave/brave-core#10038

Comments

@atuchin-m
Copy link
Contributor

atuchin-m commented Sep 7, 2021

Description

Optimize page load by replacing parseDomain in native cosmetic filter implementation to the faster alternative.

Steps to Reproduce

  1. Visit a very simple HTML page like https://example.com
  2. Open Developer Tools: Performance
  3. Click record page load time.
  4. Find for parseDomain in the trace

Actual result:

  1. parseDomain exists and takes some time (>20ms), which slow down every page/frame loads
  2. it takes few additional MB for each frame.

Expected result:

Now significant speed/memory impact.

Reproduces how often:

Every time.

Brave version (brave://version info)

Version 1.31.23 Chromium: 93.0.4577.63 (Official Build) nightly (64-bit)

Version/Channel Information:

  • Can you reproduce this issue with the current release? : yes
  • Can you reproduce this issue with the beta channel? yes
  • Can you reproduce this issue with the nightly channel? yes

Other Additional Information:

  • Does the issue resolve itself when disabling Brave Shields? yes (partially: still have the same problem with brave extension)
  • Does the issue resolve itself when disabling Brave Rewards? no
  • Is the issue reproducible on the latest version of Chrome? no

brave_local_build
brave_nightly_without_shield
chrome_no_adblock

@iefremov
Copy link
Contributor

iefremov commented Sep 8, 2021

cc @antonok-edm @pes10k

@stephendonner
Copy link

@atuchin-m I've tried to reproduce the problem before I verify the fix, and on macOS, using 1.29.81 (and likely just-released 1.30.86), I can find Parse HTML and others always, but haven't-yet managed to see parseDomain in the affected build.

Would you mind recording a screencast (using https://www.cockos.com/licecap/ or similar) showing how to reproduce the issue? Thanks regardless!

@stephendonner
Copy link

Setting QA/Blocked since although there are helpful steps, I just haven't been able to reproduce the problem, to verify the fix, yet.

@atuchin-m
Copy link
Contributor Author

@stephendonner
Hi! Not sure that the steps to reproduce are absolutely correct;) The screenshot was from a dev build to give the more detailed information.

The ticket is about a performance problem, therefore the key aspect is the time of ParseHTML. And ParseDomain one of the reasons why it was slow. The other were here.
Now all issues are fixed, and we have a good performance again: I see 127ms(stable) vs 13ms (nightly).

About the ParseDomain: is harder prof by QA that this particular thing is optimised (but you can see optimization in general)
You can't see the exact function name in release builds because it's obfuscated. But you can guest we it's from the call tree.

Note that this js-function was completely removed in the PR and replaced with a native function. So you can't find it now in perf-traces after the fix.

I suggest comparing 1.30 with a recent nightly build and you see the difference in call structure and time.

Here is the gifs:
brave_nighly
brave_1_30_parse_domain
:

@stephendonner
Copy link

stephendonner commented Sep 29, 2021

Verified PASSED using

Brave 1.31.65 Chromium: 94.0.4606.61 (Official Build) dev (x86_64)
Revision 418b78f5838ed0b1c69bb4e51ea0252171854915-refs/branch-heads/4606@{#1204}
OS macOS Version 11.6 (Build 20G165)

Steps:

  1. new profile
  2. launched Brave
  3. loaded example.com
  4. opened Developer Tools -> Performance tab
  5. clicked on Start profiling and reload page
  6. clicked Stop after a couple seconds
  7. expanded the call stacks
  8. hovered over parseHTML and noted the timing in ms
  9. compared with 1.30.86

Confirmed that we went from 91.12 ms in 1.30.86 -> 9.69 ms in 1.31.65 👍

1.30.86 1.31.65
Screen Shot 2021-09-29 at 10 31 53 AM Screen Shot 2021-09-29 at 10 33 25 AM

Thanks again for your help with the testcase, @atuchin-m !


Verified PASSED using

Brave 1.31.73 Chromium: 94.0.4606.71 (Official Build) beta (64-bit)
Revision 1d32b169326531e600d836bd395efc1b53d0f6ef-refs/branch-heads/4606@{#1256}
OS Linux

Steps:

  1. new profile
  2. launched Brave
  3. loaded example.com
  4. opened Developer Tools -> Performance tab
  5. clicked on Start profiling and reload page
  6. clicked Stop after a couple seconds
  7. expanded the call stacks
  8. hovered over parseHTML and noted the timing in ms
  9. compared with 1.30.87

Confirmed that we went from 326.30 ms in 1.30.87 -> 189.80 ms in 1.31.73 👍

1.30.87 1.31.73
Screen Shot 2021-10-06 at 4 32 08 PM Screen Shot 2021-10-06 at 4 30 31 PM

@srirambv
Copy link
Contributor

srirambv commented Oct 5, 2021

Verification passed on Samsung Tab A with Android 10 running 1.31.67 x64 Beta build

  • Verified parseDomain load time reduced from 410ms to 61ms when profiled for 5 sec
1.30.86 1.31.67 Beta
image image

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