Improving DevTools startup time

Published on

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.

DevTools starting up process

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 #

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 #

Improved mechanisms

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:

  1. CL 2431864: [devtools] Reduce performance overhead of message dispatch in the front-end
  2. CL 2442012: [devtools] 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:

  1. Record trace using chrome://tracing
  2. Open DevTools-on-DevTools
  3. 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 nameNot optimized (ms)Optimized (ms)Differences (ms)Speed improvement (%)
DevTools load CPU time (ms)

Full tracing metrics comparison table

As a result, DevTools opens and works faster with less CPU usage. 🎉

Last updated: Improve article

We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.