Improving DevTools startup time
<<../../_shared/devtools-research.md>>
DevTools startup now is ~13% faster 🎉 (from 11.2s down to 10s).
TL;DR; The result is achieved by removing a redundant serialization.
Overview
While DevTools is starting up, it needs to make some calls to the V8 JavaScript engine.
The mechanism Chromium uses to send DevTools commands to V8 (and for IPC in general) is called mojo
. My teammates Benedikt Meurer and Sigurd Schneider discovered an inefficiency while working on another task, and came up with an idea to improve the process by removing two redundant steps in how these messages are sent and received.
Let us dive into how the mojo
mechanism works!
The mojo
mechanisms
There is a mojo command EvaluateScript
which runs the JS command. It serializes the whole JS command including the arguments
into a string of JavaScript source code that can be eval()
. As you might imagine, these strings can become quite long and expensive. After the command is received by V8, these strings of JavaScript code are deserialized before running. This process of serializing and deserializing for every single message creates significant overhead.
Benedikt Meurer realised that serialisation and deserialisation of the arguments
is quite expensive, and that the whole «Serialize JS command to JS string» and «Deserialize JS string» steps are redundant and can be skipped.
Technical details: RenderFrameHostImpl::ExecuteJavaScript
How we improved
We introduced another mojo API method which allows us to pass the object name, the method to be called, and the list of arguments directly, instead of having to create the string of JavaScript source code. This allows us to skip serialization & deserialization, and removes the need to parse the JavaScript code.
For technical details on how we implemented this optimization, consult these two patches:
- CL 2431864: Reduce performance overhead of message dispatch in the front-end
- CL 2442012: Use
ExecuteJavaScriptMethod
in DevTools
Impact
To measure the effectiveness of the change, we ran some measurements comparing Chromium revisions cb971089a058 and 4f213b39d581 (before and after the change).
For both revisions, we ran the following scenario 5 times:
- Record trace using
chrome://tracing
- Open DevTools-on-DevTools
- Get the recorded
CrRendererMain
trace and compare the V8-specific metrics.
Based on these experiments, DevTools opens ~13% faster (from 11.2s down to 10s) with the optimization.
Hightlights, CPU durations
Method name | Not optimized (ms) | Optimized (ms) | Differences (ms) | Speed improvement (%) |
Total | 11,213.19 | 9,953.99 | -1,259.20 | 12.65% |
v8.run | 499.67 | 3.61 | -496.06 | 12.65% |
V8.Execute | 1,654.87 | 1,349.61 | -305.25 | 3.07% |
v8.callFunction | 1,171.84 | 1,339.77 | 167.94 | -1.69% |
v8.compile | 133.93 | 3.56 | -130.37 | 1.31% |
Full tracing metrics comparison table
As a result, DevTools opens and works faster with less CPU usage. 🎉
<<../../_shared/devtools-feedback.md>>
<<../../_shared/discover-devtools-blog.md>>
This post is also available in: English