Closed Bug 1595112 Opened 6 years ago Closed 6 years ago

Improve performance of browser chrome tests by caching the CDP client code across tests of the same domain

Categories

(Remote Protocol :: Agent, enhancement, P1)

enhancement

Tracking

(firefox72 fixed)

RESOLVED FIXED
Firefox 72
Tracking Status
firefox72 --- fixed

People

(Reporter: whimboo, Assigned: whimboo)

References

Details

(Whiteboard: [puppeteer-alpha])

Attachments

(2 files)

As discovered on bug 1592311 the browser chrome tests perform very badly. Especially for debug builds. One reason is that for each test the ~880kb CDP client code [1] needs to be loaded [2].

[1] https://searchfox.org/mozilla-central/source/remote/test/browser/chrome-remote-interface.js
[2] https://searchfox.org/mozilla-central/rev/b2b0077c2e6a516a76bf8077d6f0237c58f5959a/remote/test/browser/head.js#103-136

getCDP calls createTestDocument which is part of a hidden window, which gets closed after each test.

Caching this hidden window and not closing it until the browser shutdown, should give me a 1s improvement per single test.

Note that by loading the CDP client via Services.scriptloader.loadSubScript() instead of a script tag in the document saves us already quiet a bit of time. Especially the very first load of the JS file takes way longer with <script>. Here an example of the 5 screenshot tests:

script tag:

0:05.75 INFO *** 1573485498399 before get CDP
0:07.30 INFO *** 1573485499944 after get CDP
0:09.13 INFO *** 1573485501774 before get CDP
0:09.47 INFO *** 1573485502117 after get CDP
0:11.22 INFO *** 1573485503870 before get CDP
0:11.57 INFO *** 1573485504219 after get CDP
0:13.37 INFO *** 1573485506019 before get CDP
0:13.74 INFO *** 1573485506390 after get CDP
0:15.92 INFO *** 1573485508564 before get CDP
0:16.35 INFO *** 1573485508992 after get CDP

0.00s user 0.01s system 0% cpu 29.082 total

loadSubScript:
0:06.11 INFO *** 1573485590261 before get CDP
0:06.28 INFO *** 1573485590428 after get CDP
0:08.16 INFO *** 1573485592310 before get CDP
0:08.26 INFO *** 1573485592407 after get CDP
0:10.24 INFO *** 1573485594388 before get CDP
0:10.33 INFO *** 1573485594478 after get CDP
0:12.44 INFO *** 1573485596593 before get CDP
0:12.54 INFO *** 1573485596690 after get CDP
0:14.44 INFO *** 1573485598589 before get CDP
0:14.53 INFO *** 1573485598685 after get CDP

0.00s user 0.01s system 0% cpu 27.312 total

Andreas, is it ok to change the way how the CDP client gets injected? I'm not sure what the original purpose was to have it reside inside a script tag.

Otherwise I can't see how we could improve the performance when calling CDP() itself to get the client. It's external code which would mean a fix in that remote repo. That's not something what I would like to do right now.

Flags: needinfo?(ato)

(In reply to Henrik Skupin (:whimboo) [⌚️UTC+2] from comment #2)

Andreas, is it ok to change the way how the CDP client gets
injected? I'm not sure what the original purpose was to have it
reside inside a script tag.

Otherwise I can't see how we could improve the performance when
calling CDP() itself to get the client. It's external code which
would mean a fix in that remote repo. That's not something what I
would like to do right now.

If it doesn’t cause any regressions, I shouldn’t expect changing
it to be a problem.

You may want to check with ochameau who did the initial work on
this to see if there’s a special reason it is not loaded as a
subscript.

Flags: needinfo?(ato)

I haven't heard back from Alexandre so far. Maybe he is away. But yes, there are no regressions expected. Using the subscript loader will allow us to cache the file, what's not working when it is injected as a script node into the document of the hidden window.

At the same time I will also update the chrome-remote-interface.js client to a newer version, and also import the minimized version. That reduces the file size from 880kb to 550kb only.

https://treeherder.mozilla.org/#/jobs?repo=try&revision=7eedca381910a44911250681dae1489c1787a8e5

Using the minimized version reduces the file size from 880kB
to 550kB, which means lesser data to load and to cache.

Imported revision: f412dd1ed0028bcf9116918879b99924039d52e2

By using loadSubScript() instead of injecting a script node
into the hidden window, the content of chrome-remote-interface.js
can be cached. Only the first load will take about 150ms, each
test afterward will only have to spend about 30ms in getCDP().

Depends on D53072

Pushed by hskupin@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/f7094144a9f0 [remote] Import minimized version of chrome-remote-interface.js. r=remote-protocol-reviewers,ato https://hg.mozilla.org/integration/autoland/rev/b80efaa3e184 [remote] Cache chrome-remote-interface.js between browser chrome tests. r=remote-protocol-reviewers,ato
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 72
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: