<?xml version="1.0" encoding="utf-8" standalone="yes"?><?xml-stylesheet href="/feed.css?v=67325d779b74" type="text/css"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:site="https://lalitm.com/feed/ns#"><channel><title>Lalit Maganti (Tag: Performance)</title><link>https://lalitm.com/tags/performance/</link><description>Recent content tagged Performance on Lalit Maganti</description><site:notice>This is a feed.
Feeds let you subscribe to updates from this site using a feed reader. Copy this page's URL from your address bar and paste it into your reader.
New to feeds? Read: https://aboutfeeds.com</site:notice><docs>https://aboutfeeds.com</docs><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Sat, 12 Sep 2026 14:38:00 +0100</lastBuildDate><atom:link href="https://lalitm.com/tags/performance/index.xml" rel="self" type="application/rss+xml"/><item><title>I made a build visualizer to understand Bun’s compile times</title><link>https://lalitm.com/post/buildprof/</link><pubDate>Sat, 12 Sep 2026 14:38:00 +0100</pubDate><guid>https://lalitm.com/post/buildprof/</guid><description>I built buildprof (Github), an open-source tracing tool that shows where the time goes when you compile software on Linux. Here’s a realtime video of it profiling a clean build of ripgrep:
Watch the buildprof demo
Sometimes, builds are slow because there is simply a lot of code to compile. But more often than not, there are fixable problems: poor parallelism, repeated work, dependency downloads or a huge compiler/linker invocation. buildprof makes all of this clearly visible, so you can see what’s worth investigating and optimizing.
You run it by putting buildprof -- in front of any build command you already use:
buildprof -- make -j16 buildprof -- cargo build buildprof -- ninja -C out/target buildprof -- just build buildprof -- ./dev/custom-build-script.sh buildprof records every process your build command launches, including their subprocesses (and their subprocesses…), and lays them out on one timeline. Time moves from left to right, bar width shows duration, and child processes appear beneath whatever launched them.</description><content:encoded>&lt;p&gt;I built &lt;a href="https://buildprof.lalitm.com"&gt;buildprof&lt;/a&gt;
(&lt;a href="https://github.com/lalitMaganti/buildprof"&gt;Github&lt;/a&gt;), an open-source tracing
tool that shows where the time goes when you compile software on Linux. Here&amp;rsquo;s a
realtime video of it profiling a clean build of ripgrep:&lt;/p&gt;
&lt;p&gt;&lt;video src="https://lalitm.com/assets/buildprof/buildprof-initial-demo-v2.mp4" autoplay muted loop playsinline style="width: 100%;"&gt;&lt;a href="https://lalitm.com/assets/buildprof/buildprof-initial-demo-v2.mp4"&gt;Watch the buildprof demo&lt;/a&gt;&lt;/video&gt;&lt;/p&gt;
&lt;p&gt;Sometimes, builds are slow because there is simply a lot of code to compile. But
more often than not, there are fixable problems: poor parallelism, repeated
work, dependency downloads or a huge compiler/linker invocation. buildprof makes
all of this clearly visible, so you can see what’s worth investigating and
optimizing.&lt;/p&gt;
&lt;p&gt;You run it by putting &lt;code&gt;buildprof --&lt;/code&gt; in front of any build command you already
use:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-sh" data-lang="sh"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;buildprof -- make -j16
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;buildprof -- cargo build
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;buildprof -- ninja -C out/target
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;buildprof -- just build
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;buildprof -- ./dev/custom-build-script.sh
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;buildprof records every process your build command launches, including their
subprocesses (and their subprocesses&amp;hellip;), and lays them out on one timeline.
Time moves from left to right, bar width shows duration, and child processes
appear beneath whatever launched them.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/assets/buildprof/ripgrep-overview.png" alt="A ripgrep build: Cargo spans the whole build, rustc invocations compile crates in parallel, and the final rustc invocation launches a linker chain."&gt;&lt;/p&gt;
&lt;p&gt;I made buildprof because
&lt;a href="https://x.com/jarredsumner/status/2090619419059974620"&gt;this tweet&lt;/a&gt; from Jarred
Sumner, chief architect of the Bun JavaScript runtime, was living rent free in
my head:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/assets/buildprof/jarred-bun-rust-compile-times.png" alt="Jarred Sumner&amp;rsquo;s comparison showing a 30 minute 6 second median Linux build for Bun 1.3.14 and 5 minute 37 second median for Bun 1.4.0."&gt;&lt;/p&gt;
&lt;p&gt;Specifically, the claim that Bun’s new Rust build was &amp;gt;5× faster on Linux than
its old Zig build really bothered me. In my experience, Zig projects had usually
compiled &lt;em&gt;much&lt;/em&gt; faster than Rust projects of similar complexity. That intuition
was enough to make me feel there was a mystery to solve.&lt;/p&gt;
&lt;p&gt;This was further compounded by another important, yet easily missed, detail in
the tweet: the Zig build used Full LTO, while the Rust build used ThinLTO.&lt;/p&gt;
&lt;p&gt;Compilers normally optimize separate compilation units largely in
isolation.&lt;sup id="fnref:1"&gt;&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref"&gt;1&lt;/a&gt;&lt;/sup&gt; Link-time optimization (LTO) lets them optimize
&lt;strong&gt;across&lt;/strong&gt; those boundaries. Full LTO brings those units together into one large
optimization job, while ThinLTO preserves more separation so much of the work
can run in parallel.&lt;/p&gt;
&lt;p&gt;From past experience, this difference can have an &lt;strong&gt;enormous&lt;/strong&gt; effect on build
time. The tweet mentioned it in passing, but I wondered how much of the headline
improvement it explained.&lt;/p&gt;
&lt;p&gt;I started by trying to reproduce the numbers.&lt;/p&gt;
&lt;h2 id="the-numbers-reproduced-but-now-what"&gt;The numbers reproduced. But now what?&lt;a class="heading-anchor" href="#the-numbers-reproduced-but-now-what" aria-label="Permalink to The numbers reproduced. But now what?"&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I checked out
&lt;a href="https://github.com/oven-sh/bun/releases/tag/bun-v1.3.14"&gt;Bun 1.3.14&lt;/a&gt; and
&lt;a href="https://github.com/oven-sh/bun/releases/tag/bun-v1.4.0"&gt;Bun 1.4.0&lt;/a&gt; and wrote
&lt;a href="https://github.com/LalitMaganti/blog-code/tree/main/buildprof-bun"&gt;some scripts&lt;/a&gt;
to replay their Linux x64 CI builds on a 6-core, 12-thread Linux VM. The scripts
preserved the build steps and their dependencies, running everything on one
machine.&lt;sup id="fnref:2"&gt;&lt;a href="#fn:2" class="footnote-ref" role="doc-noteref"&gt;2&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;My timings were in the same ballpark as Jarred’s:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Linux x64 build&lt;/th&gt;
&lt;th style="text-align: right"&gt;Zig era&lt;/th&gt;
&lt;th style="text-align: right"&gt;Rust era&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Bun&amp;rsquo;s reported CI median&lt;/td&gt;
&lt;td style="text-align: right"&gt;30m06s&lt;/td&gt;
&lt;td style="text-align: right"&gt;5m37s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;My single-machine CI-profile replay&lt;/td&gt;
&lt;td style="text-align: right"&gt;24m24s&lt;/td&gt;
&lt;td style="text-align: right"&gt;5m40s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;OK, so the gap showed up on my machine too. But a lot had changed between the
two measurements besides the language; so what was actually responsible? Was it
the Zig compiler that was taking all that extra time? Or maybe it was the Full
LTO link? Or perhaps there was something else in Bun’s build I hadn’t even
thought to look at?&lt;/p&gt;
&lt;p&gt;This is where my profiling and developer-tools brain kicked in. Usually, when
I’m trying to understand why something is slow, I want a trace: what happened,
when it happened and how long it took. It would be really cool to have that for
these builds, to put them on a timeline and see where their time actually went.&lt;/p&gt;
&lt;p&gt;But a build involves a lot of different tools, each with its own idea of what’s
happening. What could I record that would let me see across all of them?&lt;/p&gt;
&lt;h2 id="builds-are-process-trees"&gt;Builds are process trees&lt;a class="heading-anchor" href="#builds-are-process-trees" aria-label="Permalink to Builds are process trees"&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;When you type &lt;code&gt;cargo build&lt;/code&gt; or &lt;code&gt;zig build&lt;/code&gt;, it feels like you are running one
program. The build system works out what needs to be rebuilt, the ordering
between those pieces and what can run in parallel. But generally, it does not
perform all that work itself; it launches compilers, code generators, archivers,
linkers and arbitrary scripts. Which can launch more programs which launch some
more…&lt;/p&gt;
&lt;p&gt;Different build systems describe that work in different ways. Cargo sees crates,
Ninja sees build edges and CMake generates instructions for another build
system. From the operating system&amp;rsquo;s point of view, however, they (mostly) look
like processes launching other processes.&lt;sup id="fnref:3"&gt;&lt;a href="#fn:3" class="footnote-ref" role="doc-noteref"&gt;3&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;A Rust build, for example, might contain a chain like this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cargo
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;└── rustc
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; └── cc
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; └── collect2
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; └── ld.lld
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If we record when each subprocess starts and ends, we can lay them out on a
timeline. Here’s what that chain looks like in buildprof:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/assets/buildprof/ripgrep-process-chain.png" alt="The final link in a ripgrep build, showing cargo launching rustc, then cc, collect2 and ld.lld beneath it."&gt;&lt;/p&gt;
&lt;p&gt;There are also several nice properties to visualizing a build at this layer:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;It&amp;rsquo;s build-system agnostic&lt;/strong&gt;: Cargo, Ninja, Zig, Make and most other build
systems do much of their work by spawning processes, so we do not need to
write a special integration for each one.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;It naturally includes custom scripts&lt;/strong&gt;: This includes both scripts above
the build system (repository setup, dependency fetching) and scripts
underneath it (code generators, asset processors).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;We can follow the files between build steps&lt;/strong&gt;: recording which files each
process reads and writes lets us see which steps produce the inputs for
others. This even works across build systems!&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This gave me a starting point for buildprof: record the process tree, then turn
it into a timeline I could explore. There are plenty more details to get into,
which I will do later. But once I had that working, I could finally go back to
my initial question: what was Bun doing for those twenty-four minutes?&lt;/p&gt;
&lt;h2 id="pointing-it-at-bun"&gt;Pointing it at Bun&lt;a class="heading-anchor" href="#pointing-it-at-bun" aria-label="Permalink to Pointing it at Bun"&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;h3 id="why-was-the-zig-ci-build-so-much-slower"&gt;Why was the Zig CI build so much slower?&lt;a class="heading-anchor" href="#why-was-the-zig-ci-build-so-much-slower" aria-label="Permalink to Why was the Zig CI build so much slower?"&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;I started by recording the Zig-era CI build with buildprof, using the
&lt;a href="https://github.com/LalitMaganti/blog-code/blob/main/buildprof-bun/scripts/record-original-zig-ci.sh"&gt;same scripts as before&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/assets/buildprof/zig-ci-overview-notes.png" alt="The complete Zig-era CI build"&gt;&lt;/p&gt;
&lt;p style="text-align: center;"&gt;&lt;em&gt;&lt;a href="https://buildprof.lalitm.com/v0.2.2/#!/?url=https%3A%2F%2Fblogexamples.lalitm.com%2Fbuildprof-bun%2F2026-09-04%2Fbun-zig-original-ci-b5a45845003ecae0.buildprof"&gt;Explore in buildprof&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Right away we can see a huge problem: the &lt;code&gt;ld.lld&lt;/code&gt; linker invocation &lt;em&gt;dominates&lt;/em&gt;
the build time. It ran alone at the very end for over sixteen minutes, about
two-thirds of the entire build. What the heck was it doing for all that time?&lt;/p&gt;
&lt;p&gt;Clicking on the linker shows its command line, which buildprof captures
automatically:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/assets/buildprof/zig-full-lto-command-notes.png" alt="The selected Zig-era linker and its Full LTO flag"&gt;&lt;/p&gt;
&lt;p&gt;There’s Full LTO, just as Jarred said. Given how long the link was taking, it
was now my main suspect.&lt;/p&gt;
&lt;p&gt;But the process tree alone couldn’t tell me whether LTO was actually responsible
for those sixteen minutes. Thankfully, LLD records its own internal timing
events, and buildprof can include them when you use &lt;code&gt;--compiler-traces&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I
&lt;a href="https://github.com/LalitMaganti/blog-code/blob/main/buildprof-bun/scripts/record-zig-full-lto-link-detail.sh"&gt;recorded the final link again&lt;/a&gt;,
this time with &lt;code&gt;--compiler-traces&lt;/code&gt; enabled:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/assets/buildprof/zig-full-lto-linker-internals-notes.png" alt="LLD&amp;rsquo;s internal phases"&gt;&lt;/p&gt;
&lt;p style="text-align: center;"&gt;&lt;em&gt;&lt;a href="https://buildprof.lalitm.com/v0.2.2/#!/?url=https%3A%2F%2Fblogexamples.lalitm.com%2Fbuildprof-bun%2F2026-09-04%2Fbun-zig-full-lto-link-detail-d1e7a0e1dd7750d4.buildprof"&gt;Explore in buildprof&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Now we can see that LTO &lt;em&gt;is&lt;/em&gt; where almost all the time goes. The linker is
running compiler passes over the program, not just combining already-compiled
files. The &lt;code&gt;OptModule&lt;/code&gt; bar alone takes just over ten minutes and includes the
passes which generate machine code.&lt;sup id="fnref:4"&gt;&lt;a href="#fn:4" class="footnote-ref" role="doc-noteref"&gt;4&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;h4 id="how-did-the-rust-ci-build-differ"&gt;How did the Rust CI build differ?&lt;a class="heading-anchor" href="#how-did-the-rust-ci-build-differ" aria-label="Permalink to How did the Rust CI build differ?"&gt;#&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;With so much of the Zig build spent in LTO, I wanted to see how much time the
Rust build spent linking. I recorded that build too:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/assets/buildprof/rust-ci-overview-notes.png" alt="The complete Rust-era CI build"&gt;&lt;/p&gt;
&lt;p style="text-align: center;"&gt;&lt;em&gt;&lt;a href="https://buildprof.lalitm.com/v0.2.2/#!/?url=https%3A%2F%2Fblogexamples.lalitm.com%2Fbuildprof-bun%2F2026-09-04%2Fbun-rust-original-ci-4c9dbcbe6d041d98.buildprof"&gt;Explore in buildprof&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Just 2m24s. And this time, as expected, the linker command contains
&lt;code&gt;-plugin-opt=thinlto&lt;/code&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/assets/buildprof/rust-ci-thinlto-notes.png" alt="The Rust linker invocation with ThinLTO enabled"&gt;&lt;/p&gt;
&lt;p&gt;Both builds were doing LTO, but with different settings and very different link
times. What if I kept Bun’s Zig code and changed Full LTO to ThinLTO? How much
of the gap would that close?&lt;/p&gt;
&lt;h4 id="trying-thinlto"&gt;Trying ThinLTO&lt;a class="heading-anchor" href="#trying-thinlto" aria-label="Permalink to Trying ThinLTO"&gt;#&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;I
&lt;a href="https://github.com/LalitMaganti/blog-code/blob/main/buildprof-bun/patches/zig-thinlto.patch"&gt;switched Zig Bun’s build flags to ThinLTO&lt;/a&gt;
and recorded another clean build, along with a fresh Full-LTO build for
comparison:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/assets/buildprof/zig-lto-pair-comparison-notes.png" alt="The matched Full-LTO build and partial ThinLTO experiment"&gt;&lt;/p&gt;
&lt;p style="text-align: center;"&gt;&lt;em&gt;Explore in buildprof: &lt;a href="https://buildprof.lalitm.com/v0.2.2/#!/?url=https%3A%2F%2Fblogexamples.lalitm.com%2Fbuildprof-bun%2F2026-09-04%2Fbun-zig-ci-dag-full-lto-6111eb9fd9486a35.buildprof"&gt;Full LTO&lt;/a&gt; · &lt;a href="https://buildprof.lalitm.com/v0.2.2/#!/?url=https%3A%2F%2Fblogexamples.lalitm.com%2Fbuildprof-bun%2F2026-09-04%2Fbun-zig-ci-dag-thin-lto-fdfb05e3d506d810.buildprof"&gt;partial ThinLTO&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The link got 3m40s faster in this pair of recordings, but it was still taking
nearly thirteen minutes. Why was linking still so expensive?&lt;/p&gt;
&lt;p&gt;Looking back at the compiler trace, a lot of the work was on functions with
&lt;code&gt;JSC&lt;/code&gt; in their names. That’s JavaScriptCore, the engine Bun uses to execute
JavaScript. The linker was spending time compiling the JavaScript engine
too.&lt;sup id="fnref:5"&gt;&lt;a href="#fn:5" class="footnote-ref" role="doc-noteref"&gt;5&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;Clicking on the linker invocation showed the
&lt;a href="https://github.com/oven-sh/WebKit/tree/5488984d20e0dbfe4be2c3ba8fb18eb81a5e0e8b"&gt;WebKit&lt;/a&gt;
libraries among its inputs, including &lt;code&gt;libJavaScriptCore.a&lt;/code&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/assets/buildprof/zig-thinlto-webkit-inputs-notes.png" alt="The linker command has ThinLTO enabled but still includes WebKit’s libraries, including libJavaScriptCore.a."&gt;&lt;/p&gt;
&lt;p&gt;Following those inputs back through the build, I found that Bun wasn’t compiling
these libraries itself. It was downloading them from a separate WebKit build.
And when I checked
&lt;a href="https://github.com/oven-sh/WebKit/blob/5488984d20e0dbfe4be2c3ba8fb18eb81a5e0e8b/Dockerfile#L4"&gt;that build’s flags&lt;/a&gt;,
there it was again: &lt;code&gt;-flto=full&lt;/code&gt;. The Rust build used a newer WebKit revision
whose
&lt;a href="https://github.com/oven-sh/WebKit/blob/0f966e81b78c84bb/Dockerfile#L4"&gt;build recipe selected ThinLTO&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Even though I had changed how Bun compiled its own code, those downloaded
libraries still contained Full-LTO inputs and so the linker still had to
optimize that code and turn it into machine code. To change that, I would have
to rebuild WebKit too.&lt;/p&gt;
&lt;h4 id="rebuilding-webkit"&gt;Rebuilding WebKit&lt;a class="heading-anchor" href="#rebuilding-webkit" aria-label="Permalink to Rebuilding WebKit"&gt;#&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;I checked out the historical WebKit revision and rebuilt it and its ICU
dependencies with compatible ThinLTO settings. Then I replaced the downloaded
libraries with the ones I had built, keeping the ThinLTO changes to Bun.&lt;/p&gt;
&lt;p&gt;Here are the recorded builds:&lt;sup id="fnref:6"&gt;&lt;a href="#fn:6" class="footnote-ref" role="doc-noteref"&gt;6&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Zig-era build&lt;/th&gt;
&lt;th style="text-align: right"&gt;Whole build&lt;/th&gt;
&lt;th style="text-align: right"&gt;Final linker&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Original Full LTO&lt;/td&gt;
&lt;td style="text-align: right"&gt;24m24s&lt;/td&gt;
&lt;td style="text-align: right"&gt;16m35s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bun ThinLTO; original WebKit archives&lt;/td&gt;
&lt;td style="text-align: right"&gt;20m20s&lt;/td&gt;
&lt;td style="text-align: right"&gt;12m55s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bun ThinLTO; rebuilt ThinLTO WebKit and ICU&lt;/td&gt;
&lt;td style="text-align: right"&gt;15m11s&lt;/td&gt;
&lt;td style="text-align: right"&gt;7m22s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The link now took 7m22s. Still slower than the Rust build, but enough of an
improvement that I wanted to look beyond the linker.&lt;/p&gt;
&lt;h4 id="what-about-the-rest-of-the-build"&gt;What about the rest of the build?&lt;a class="heading-anchor" href="#what-about-the-rest-of-the-build" aria-label="Permalink to What about the rest of the build?"&gt;#&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;The build still took fifteen minutes, and nearly eight of those passed before
the linker even started. What was it waiting for? I went back to the original CI
trace to follow the inputs from Bun’s own code.&lt;/p&gt;
&lt;p&gt;buildprof also records which files each process reads and writes. If a process
reads a file another wrote, it links the two together under the hood. Turning on
“Show on timeline” draws those links as arrows. Here, the linker reads
&lt;code&gt;libbun-profile.a&lt;/code&gt; from the C++ compilation and &lt;code&gt;bun-zig.o&lt;/code&gt; from Zig. Both
arrive through copy steps; following those back takes us to the processes which
produced them:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/assets/buildprof/zig-ci-dependency-combined-notes.png" alt="Following the linker’s dependency arrows through the copy steps to the C++ and Zig producers. The producer panels use the same time scale; C++ finishes first."&gt;&lt;/p&gt;
&lt;p&gt;The C++ side of the compilation finished first. The linker was waiting for
&lt;code&gt;bun-zig.o&lt;/code&gt;, so it could not begin until the Zig branch had finished too.&lt;/p&gt;
&lt;p&gt;It was at this point I went back to the Rust build and compared against how it
worked, and the main reason the Rust build was faster became obvious: Bun has
been split into &amp;gt;90 crates, while in Zig it was all trying to compile as a
single Zig module!&lt;/p&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/assets/buildprof/rust-crates-vs-zig-object-notes.png" alt="Cargo fanning out into named rustc processes across Bun’s crates, next to the single zig build-obj process which spawns nothing at all."&gt;&lt;/p&gt;
&lt;p&gt;This meant that the Zig build cannot parallelise the same way Rust can. I also
suspect, though I did not prove this, that it explains the slow linking: the
linker has to optimize one huge ThinLTO bitcode module instead of the same work
spread across crates.&lt;/p&gt;
&lt;p&gt;It was at this point I had to stop: to go any further, I would have to split up
the Zig module myself, and given that this code is all obsolete anyway, I didn&amp;rsquo;t
think it was worth doing that.&lt;/p&gt;
&lt;p&gt;Summarizing:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The huge outlier in the initial Zig build vs the Rust build was the massive
linker step which ran alone at the end of the build.&lt;/li&gt;
&lt;li&gt;Changing the LTO settings for just Bun was not sufficient as WebKit, a
significant part of the build, still used Full LTO.&lt;/li&gt;
&lt;li&gt;Once I had done this, the Zig build dropped from twenty-four minutes to
fifteen.&lt;/li&gt;
&lt;li&gt;Even after this, linking still took 7 minutes and the whole build 15 minutes.&lt;/li&gt;
&lt;li&gt;The overwhelming difference which remained was structural: Rust spreads
compilation across &amp;gt;90 crates while the Zig build funnelled everything through
a single module.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And fwiw, the traces had also turned up a few things I couldn’t resist poking
at&amp;hellip;&lt;/p&gt;
&lt;h3 id="other-things-hiding-in-the-build"&gt;Other things hiding in the build&lt;a class="heading-anchor" href="#other-things-hiding-in-the-build" aria-label="Permalink to Other things hiding in the build"&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;h4 id="a-build-can-contain-almost-anything"&gt;A build can contain almost anything&lt;a class="heading-anchor" href="#a-build-can-contain-almost-anything" aria-label="Permalink to A build can contain almost anything"&gt;#&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;In the middle of Bun’s CI build, I found commands asking the public internet for
the machine’s IP address, inspecting running Docker containers and reading the
latest Git commit message.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/assets/buildprof/zig-ci-diagnostic-probes-notes.png" alt="Small CI setup commands visible in the process tree"&gt;&lt;/p&gt;
&lt;p&gt;These take well under a second altogether. Nothing to optimize but I just wasn’t
expecting to find them in a build trace.&lt;/p&gt;
&lt;h4 id="a-cold-dependency-fetch"&gt;A cold dependency fetch&lt;a class="heading-anchor" href="#a-cold-dependency-fetch" aria-label="Permalink to A cold dependency fetch"&gt;#&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;The builds above reused downloaded dependencies, so I also
&lt;a href="https://github.com/LalitMaganti/blog-code/blob/main/buildprof-bun/scripts/capture-bun-cold-prebuilt.sh"&gt;recorded a fresh WebKit fetch&lt;/a&gt;.
Downloading and extracting the archive took about twenty seconds. For the first
twelve, all we see is Node running. Then it launches &lt;code&gt;tar&lt;/code&gt; and &lt;code&gt;gzip&lt;/code&gt;, and we
can see the extraction separately.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/assets/buildprof/zig-cold-webkit-download-article.png" alt="A cold WebKit download and extraction"&gt;&lt;/p&gt;
&lt;h4 id="looking-inside-one-c-compilation"&gt;Looking inside one C++ compilation&lt;a class="heading-anchor" href="#looking-inside-one-c-compilation" aria-label="Permalink to Looking inside one C&amp;#43;&amp;#43; compilation"&gt;#&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;Earlier, we followed the linker’s inputs back to Bun’s C++ compilation. We can
look inside those compiler invocations too. I picked one of the last files to
finish, &lt;code&gt;ZigGeneratedClasses.cpp&lt;/code&gt;, and
&lt;a href="https://github.com/LalitMaganti/blog-code/blob/main/buildprof-bun/scripts/capture-bun-compiler-detail.sh"&gt;replayed its Ninja command&lt;/a&gt;
with &lt;code&gt;--compiler-traces&lt;/code&gt;. For Clang, buildprof enables &lt;code&gt;-ftime-trace&lt;/code&gt; and adds
its internal timings to the process timeline.&lt;sup id="fnref:7"&gt;&lt;a href="#fn:7" class="footnote-ref" role="doc-noteref"&gt;7&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/assets/buildprof/zig-generated-classes-compiler-phases-article.png" alt="Clang’s frontend and backend phases while compiling ZigGeneratedClasses.cpp"&gt;&lt;/p&gt;
&lt;p&gt;The replay took about twelve seconds, split almost evenly between Clang’s
frontend and backend. Zooming in further, we see &lt;code&gt;ModuleInlinerWrapperPass&lt;/code&gt;, one
of the phases of Clang, accounts for over four seconds of the backend’s work.&lt;/p&gt;
&lt;h2 id="how-buildprof-works-under-the-hood"&gt;How buildprof works under the hood&lt;a class="heading-anchor" href="#how-buildprof-works-under-the-hood" aria-label="Permalink to How buildprof works under the hood"&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The recording side of buildprof uses &lt;code&gt;ptrace&lt;/code&gt;, the same Linux interface used by
debuggers. I did consider both eBPF and ftrace, but &lt;code&gt;ptrace&lt;/code&gt; is just straight up
perfect for exactly this type of problem; eBPF tracing means &lt;code&gt;CAP_BPF&lt;/code&gt; and
&lt;code&gt;CAP_PERFMON&lt;/code&gt; permissions and hooking into potentially unstable
tracepoints/kernel functions. While with ftrace, I’d have to juggle tracing
instances to avoid interfering with other users, and getting the filters perfect
for just the build process and all its descendants is
cumbersome.&lt;sup id="fnref:8"&gt;&lt;a href="#fn:8" class="footnote-ref" role="doc-noteref"&gt;8&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;With &lt;code&gt;ptrace&lt;/code&gt;, I can launch the build and follow its children directly. Its
built-in events tell buildprof when processes fork, exec a new program or exit.
And for filesystem activity, buildprof uses a seccomp filter to intercept only
the calls it needs.&lt;/p&gt;
&lt;p&gt;How much buildprof costs is almost entirely down to how many files the build
opens. For ripgrep, recording barely changed the build time. Redis opened files
much more often, and recording added about five seconds:&lt;sup id="fnref:9"&gt;&lt;a href="#fn:9" class="footnote-ref" role="doc-noteref"&gt;9&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Build&lt;/th&gt;
&lt;th style="text-align: right"&gt;Untraced&lt;/th&gt;
&lt;th style="text-align: right"&gt;Processes only&lt;/th&gt;
&lt;th style="text-align: right"&gt;Processes + files&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;ripgrep / Cargo&lt;/td&gt;
&lt;td style="text-align: right"&gt;12.27s&lt;/td&gt;
&lt;td style="text-align: right"&gt;12.30s&lt;/td&gt;
&lt;td style="text-align: right"&gt;12.43s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Redis / Make&lt;/td&gt;
&lt;td style="text-align: right"&gt;26.78s&lt;/td&gt;
&lt;td style="text-align: right"&gt;27.04s&lt;/td&gt;
&lt;td style="text-align: right"&gt;31.89s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;If that overhead gets in the way, you can turn off filesystem tracing with
&lt;code&gt;--no-file-events&lt;/code&gt; and keep the process timeline.&lt;/p&gt;
&lt;p&gt;I work on &lt;a href="https://github.com/google/perfetto"&gt;Perfetto&lt;/a&gt;, so it was a natural
starting point for the UI; buildprof’s UI is a soft fork of the Perfetto UI. I
could have just opened the recordings on
&lt;a href="https://ui.perfetto.dev"&gt;ui.perfetto.dev&lt;/a&gt;, but I wanted control over how the
process tree was laid out, which details appeared when you clicked a command,
and things like those on-demand arrows between file producers and consumers.&lt;/p&gt;
&lt;p&gt;Fortunately, we&amp;rsquo;ve spent the last several years working on making the Perfetto
UI extensible through
&lt;a href="https://perfetto.dev/docs/contributing/ui-plugins"&gt;plugins&lt;/a&gt;. Most of
buildprof’s UI is reusing that infrastructure. Perfetto handles the hard stuff
(parsing traces, querying events, rendering the timeline and managing
workspaces) and I get to focus on what makes those things useful for builds.&lt;/p&gt;
&lt;p&gt;I plan on going into a lot more detail about the recorder and UI in a separate
technical post. &lt;a href="https://lalitm.com/page/subscribe/"&gt;Subscribe&lt;/a&gt; if you’d like to
be notified when it comes out! :)&lt;/p&gt;
&lt;h2 id="did-i-need-to-build-something-new"&gt;Did I need to build something new?&lt;a class="heading-anchor" href="#did-i-need-to-build-something-new" aria-label="Permalink to Did I need to build something new?"&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;These days it&amp;rsquo;s very easy to make a tool just because you can. But that wasn’t
the case here; before building buildprof, I looked long and hard for an existing
tool that could give me this view.&lt;/p&gt;
&lt;p&gt;I started with &lt;a href="https://github.com/nico/ninjatracing"&gt;ninjatracing&lt;/a&gt;, which I’ve
used many times. It turns Ninja’s build log into a timeline showing what ran and
how much ran in parallel.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://ui.perfetto.dev/#!/?url=https%3A%2F%2Fraw.githubusercontent.com%2FLalitMaganti%2Fblog-code%2Fmain%2Fbuildprof-bun%2Fresults%2Fbun-zig-ci-ninjatracing.json"&gt;Here’s the Ninja log from the Zig-era build&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;But Ninja only sees part of Bun’s build. The scripts which invoke it are missing
from its log, and commands it runs appear as single blocks even when they launch
whole trees of subprocesses.&lt;/p&gt;
&lt;p&gt;There were several other tools, each covering different parts of the problem:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://doc.rust-lang.org/cargo/reference/timings.html"&gt;Cargo timings&lt;/a&gt; works
well for Cargo-managed builds, but cannot break down arbitrary work inside
&lt;code&gt;build.rs&lt;/code&gt; or see wrapper scripts above Cargo. In Bun, Cargo is only part of
the build:
&lt;a href="https://lalitm.com/assets/buildprof/bun-rust-ci-cargo-timings.html"&gt;the report I captured&lt;/a&gt;
covered 1m51s of a 5m40s CI build.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-ftime-trace"&gt;Clang’s &lt;code&gt;-ftime-trace&lt;/code&gt;&lt;/a&gt;
gave us the detail inside a compiler invocation, but cannot show what the rest
of the build is doing while
&lt;a href="https://ziglang.org/learn/overview/#performance-and-safety-choose-two"&gt;Zig&amp;rsquo;s Tracy integration&lt;/a&gt;
goes deeper still and is intended more for understanding the compiler itself.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://strace.io/"&gt;&lt;code&gt;strace&lt;/code&gt;&lt;/a&gt; and
&lt;a href="https://github.com/kxxt/tracexec"&gt;&lt;code&gt;tracexec&lt;/code&gt;&lt;/a&gt; can follow arbitrary processes
through &lt;code&gt;fork&lt;/code&gt; and &lt;code&gt;exec&lt;/code&gt;, but show general process events rather than a
build-oriented timeline.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="https://danielchasehooper.com/posts/syscall-build-snooping/"&gt;What the Fork&lt;/a&gt;
(&lt;a href="https://news.ycombinator.com/item?id=44902127"&gt;via&lt;/a&gt;) came closest: it follows
processes across build systems and presents a build-specific view. But as far as
I could tell, it still appears to be in private beta and there don&amp;rsquo;t seem to be
any plans to make it open source.&lt;/p&gt;
&lt;h2 id="whats-next-for-buildprof"&gt;What’s next for buildprof&lt;a class="heading-anchor" href="#whats-next-for-buildprof" aria-label="Permalink to What’s next for buildprof"&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;buildprof already does what I wanted it to do, and I plan to keep working on it
as I use it on my own builds. But there are a few things I’d like to improve.&lt;/p&gt;
&lt;p&gt;Recording overhead is one; the Redis measurements showed there’s room to improve
filesystem tracing, especially for builds which open lots of files. I’d also
like to support &lt;a href="https://github.com/LalitMaganti/buildprof/issues/2"&gt;macOS&lt;/a&gt;
where I do some of my work and maybe
&lt;a href="https://github.com/LalitMaganti/buildprof/issues/3"&gt;Windows&lt;/a&gt; if there&amp;rsquo;s
interest.&lt;/p&gt;
&lt;p&gt;There are also more build systems and toolchains I’d like to test, including
npm, Gradle and Bazel. Computing critical paths would also be a big improvement:
we followed dependencies by hand in this post, but buildprof could help identify
the chain of work holding up the build and automatically annotate it.&lt;/p&gt;
&lt;p&gt;I’ll probably tackle these as and when I need them. But if you try buildprof and
there’s something you wish it could do, I’d be interested to
&lt;a href="https://github.com/LalitMaganti/buildprof/issues"&gt;hear about it&lt;/a&gt;. What people
find useful will help me decide where to spend more time.&lt;/p&gt;
&lt;h2 id="conclusion"&gt;Conclusion&lt;a class="heading-anchor" href="#conclusion" aria-label="Permalink to Conclusion"&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I managed to satiate my curiosity, though I ended up spending rather more time
on this than I expected. Along the way I built a tool I now want to have around
whenever a build is taking too long.&lt;/p&gt;
&lt;p&gt;I know I’ll come back to buildprof the next time a slow build annoys me. If you
have one of those builds too,
&lt;a href="https://github.com/LalitMaganti/buildprof#quick-start"&gt;give it a try&lt;/a&gt;. I’d love
to hear what you find!&lt;/p&gt;
&lt;div class="footnotes" role="doc-endnotes"&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id="fn:1"&gt;
&lt;p&gt;In C and C++, a compilation unit is usually
&lt;a href="https://eel.is/c++draft/lex.separate"&gt;a source file together with its included headers&lt;/a&gt;.
Rust compiles
&lt;a href="https://doc.rust-lang.org/reference/crates-and-source-files.html"&gt;crates&lt;/a&gt;,
which can be split into
&lt;a href="https://doc.rust-lang.org/rustc/codegen-options/#codegen-units"&gt;multiple code-generation units&lt;/a&gt;.
Zig normally compiles a program’s Zig sources together as
&lt;a href="https://kristoff.it/blog/zig-new-relationship-llvm/#speeding-up-compilation"&gt;a single compilation unit&lt;/a&gt;.
Bun’s Zig compiler fork supports splitting that into multiple LLVM modules,
but its CI build
&lt;a href="https://github.com/oven-sh/bun/blob/0d9b296af33f2b851fcbf4df3e9ec89751734ba4/scripts/build/zig.ts#L34-L62"&gt;explicitly selected one when LTO was enabled&lt;/a&gt;.&amp;#160;&lt;a href="#fnref:1" class="footnote-backref" role="doc-backlink"&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id="fn:2"&gt;
&lt;p&gt;The
&lt;a href="https://github.com/oven-sh/bun/blob/bun-v1.3.14/.buildkite/ci.mjs#L555-L609"&gt;Zig-era CI build&lt;/a&gt;
ran its C++ and Zig compilation stages on separate
&lt;a href="https://buildkite.com/home/"&gt;Buildkite&lt;/a&gt; machines and passed their outputs
to a final linking stage. My script ran those stages concurrently on one
machine, waited for both outputs, copied them locally instead of
transferring them over the network, then linked them. This should preserve
the dependency graph, but due to the hardware differences and running both
stages on one machine, resource contention would obviously be quite
different. Also note that my timings are individual runs (albeit ones which
were quite stable) while Bun’s reported figures are medians.&amp;#160;&lt;a href="#fnref:2" class="footnote-backref" role="doc-backlink"&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id="fn:3"&gt;
&lt;p&gt;A process can do substantial work internally, including running multiple
threads, without launching anything else. The process timeline won’t show
that parallelism. To see inside a process, we need tracing from the program
itself, as Clang and LLD provide in the examples below.&amp;#160;&lt;a href="#fnref:3" class="footnote-backref" role="doc-backlink"&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id="fn:4"&gt;
&lt;p&gt;LLVM emits &lt;code&gt;OptModule&lt;/code&gt; from its legacy pass manager, which LLD uses for code
generation. The inlining and other IR optimization passes can appear before
it, so this bar is not the total time spent optimizing a module.&amp;#160;&lt;a href="#fnref:4" class="footnote-backref" role="doc-backlink"&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id="fn:5"&gt;
&lt;p&gt;In the earlier Full-LTO linker replay, 26,825 &lt;code&gt;OptFunction&lt;/code&gt; events with JSC
symbols total about 209s. This is summed event time, not a measurement of
JavaScriptCore’s entire contribution to the link. One
&lt;a href="https://github.com/LalitMaganti/blog-code/blob/main/buildprof-bun/results/compiler-events/zig-full-lto-javascriptcore-event.png"&gt;example event&lt;/a&gt;
takes 2.94s; its symbol demangles to &lt;code&gt;JSC::JITThunks::initialize(JSC::VM&amp;amp;)&lt;/code&gt;.&amp;#160;&lt;a href="#fnref:5" class="footnote-backref" role="doc-backlink"&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id="fn:6"&gt;
&lt;p&gt;&lt;a href="https://github.com/LalitMaganti/blog-code/blob/main/buildprof-bun/experiments/webkit-thinlto/record-comparison.sh"&gt;Recording script&lt;/a&gt;.
These timings are just for building Bun with the libraries already
available; the WebKit and ICU rebuild happened beforehand and isn’t
included. Of course, I could point buildprof at that build too, but that’s
another rabbit hole&amp;hellip; I did not rebuild a matching Full-LTO WebKit archive
as a control, so I cannot attribute every second saved to the LTO setting
alone.&amp;#160;&lt;a href="#fnref:6" class="footnote-backref" role="doc-backlink"&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id="fn:7"&gt;
&lt;p&gt;buildprof currently supports compiler traces from Clang, LLD and nightly
Rust.&amp;#160;&lt;a href="#fnref:7" class="footnote-backref" role="doc-backlink"&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id="fn:8"&gt;
&lt;p&gt;eBPF tracing uses capabilities such as &lt;code&gt;CAP_BPF&lt;/code&gt; and &lt;code&gt;CAP_PERFMON&lt;/code&gt;, as
described in the
&lt;a href="https://android.googlesource.com/kernel/common/+/3135f5b73592988af0eb1b11ccbb72a8667be201/include/uapi/linux/capability.h"&gt;kernel’s capability definitions&lt;/a&gt;.
ftrace provides
&lt;a href="https://www.kernel.org/doc/html/latest/trace/ftrace.html"&gt;separate tracing instances and PID filters&lt;/a&gt;,
but these still need configuring and access to tracefs. &lt;code&gt;ptrace&lt;/code&gt; also
depends on the host’s security settings; containers may need additional
permissions to allow tracing child processes.&amp;#160;&lt;a href="#fnref:8" class="footnote-backref" role="doc-backlink"&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id="fn:9"&gt;
&lt;p&gt;Medians of five clean builds per mode on the same VM, with six build jobs.
&lt;a href="https://github.com/LalitMaganti/blog-code/blob/main/buildprof-bun/results/overhead/measure-options.py"&gt;Measurement script&lt;/a&gt;.&amp;#160;&lt;a href="#fnref:9" class="footnote-backref" role="doc-backlink"&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;</content:encoded></item><item><title>On "When impressive performance gains do not matter"</title><link>https://lalitm.com/post/on-when-impressive-performance/</link><pubDate>Tue, 30 Jun 2026 16:25:00 +0100</pubDate><guid>https://lalitm.com/post/on-when-impressive-performance/</guid><description>When impressive performance gains do not matter is a very nice article covering some ways in which going after performance alone is not sufficient without considering the wider picture. It resonated a lot with how I think about performance.
If there are multiple bottlenecks in the pipeline—and with these systems, this is common—the overall throughput will not improve until every last bottleneck is removed.
His focus is on distributed systems bottlenecks, but I’ve hit the same “do-nothing” speedups when optimizing client side programs. Usually this comes from spending a lot of time thinking something was the bottleneck when it wasn’t. CPU profiling is where this bites me most: it tells me “function X is taking 30% of the cycles” and I think “oooo, there’s a lot of gains to be made there”. I build a microbenchmark for X, optimize it and there’s only a marginal gain at the high level. While disappointing, I’ve become used to it over time and internalized that performance is highly non-linear and actually knowing where the problem lies is really hard.</description><content:encoded>&lt;p&gt;&lt;a href="https://blog.colinbreck.com/when-impressive-performance-gains-do-not-matter/"&gt;When impressive performance gains do not matter&lt;/a&gt;
is a very nice article covering some ways in which going after performance alone
is not sufficient without considering the wider picture. It resonated a lot with
how I think about performance.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;If there are multiple bottlenecks in the pipeline—and with these systems, this
is common—the overall throughput will not improve until every last bottleneck
is removed.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;His focus is on distributed systems bottlenecks, but I&amp;rsquo;ve hit the same
&amp;ldquo;do-nothing&amp;rdquo; speedups when optimizing client side programs. Usually this comes
from spending a lot of time &lt;em&gt;thinking&lt;/em&gt; something was the bottleneck when it
wasn&amp;rsquo;t. CPU profiling is where this bites me most: it tells me &amp;ldquo;function X is
taking 30% of the cycles&amp;rdquo; and I think &amp;ldquo;oooo, there&amp;rsquo;s a lot of gains to be made
there&amp;rdquo;. I build a microbenchmark for X, optimize it and there&amp;rsquo;s only a marginal
gain at the high level. While disappointing, I&amp;rsquo;ve become used to it over time
and internalized that performance is highly non-linear and actually knowing
where the problem lies is really hard.&lt;/p&gt;
&lt;p&gt;One specific pattern I&amp;rsquo;ve run into several times: if you are processing a lot of
data and that requires you to hit main memory, you can do quite a bit of
computation at the same time on that data for free. This is because out-of-order
processors are very good at doing computation while stalled on RAM. So removing
instructions in paths like that won&amp;rsquo;t actually matter; what matters much more is
your data structures and reducing how much memory you&amp;rsquo;re touching.&lt;/p&gt;
&lt;p&gt;While I&amp;rsquo;m on this topic, I have to shout out Matt Kulukundis&amp;rsquo;s
&lt;a href="https://www.youtube.com/watch?v=ncHmEUmJZf4"&gt;CppCon talk on Abseil&amp;rsquo;s flat hash map&lt;/a&gt;,
as it&amp;rsquo;s what helped me distill my experiences into actual rules of thumb around
building performant systems. I would highly recommend you watch it if you are
remotely interested in performance!&lt;/p&gt;
&lt;p&gt;As for the post, I also like the closing reflection:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Performance work can be incredibly challenging, but it is also a discipline
for intimately understanding complex systems and engineering better products.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;That matches my own experience: the lasting value isn&amp;rsquo;t any single speedup, it&amp;rsquo;s
the improved understanding of the system you&amp;rsquo;re building and is invaluable for
making things better in the long term.&lt;/p&gt;</content:encoded></item><item><title>Perfetto: Swiss Army Knife for Linux Client Tracing</title><link>https://lalitm.com/perfetto-swiss-army-knife/</link><pubDate>Fri, 31 Oct 2025 00:00:00 +0000</pubDate><guid>https://lalitm.com/perfetto-swiss-army-knife/</guid><description>I gave a talk at the 2025 Tracing Summit last month titled “Perfetto: The Swiss Army Knife of Linux Client/Embedded Tracing”. My goal in this talk was to show how Linux kernel, systems and embedded developers can use Perfetto when debugging and root-causing performance issues in their respective domains. Even though the Perfetto UI is primarily built for viewing Android or Chrome traces, it is a flexible tool and can be used in many other ways!
The talk was recorded and is available on YouTube. Taking inspiration from Simon Willison, this post is an annotated presentation containing my slides and detailed notes on them. The talk also has a lot of UI demos: for these, I’ll have a screenshot but also a link to the relevant part of the video (videos are unbeatable for UI!).
First, what is Perfetto? Perfetto is fundamentally a suite of tools: it’s not just one thing but a bunch of different tools working together to help you debug and root-cause problems. This diagram shows how everything fits together, with the core parts of the Perfetto project in the center.
The recording tools for Perfetto consist of 1) an SDK for C++ apps 2) a daemon that can collect data from ftrace, /proc, /sys, and various kernel interfaces 3) another daemon that amalgamates trace data from multiple processes into a single trace file. These tools all speak the Perfetto protobuf format, a high-performance trace format designed to be very efficient to write but not to analyze or consume directly.
That’s where the trace processor comes in. It’s a C++ library that parses the protobuf format, but also a bunch of other widely used trace formats. It exposes this data via an SQL query interface to any embedding program including Perfetto UI (which is what most of this talk is about) and also to the Python API if you want to do ad-hoc scripting or analysis in Python.
There are also very common tracing/profiling formats used by the Linux community: perf.data, ftrace text format, Firefox profiler format, and many others. Perfetto supports quite a few of those directly. There’s also the Chrome JSON format (AKA the Trace Event Format) which is a simpler interchange format. It’s not the most efficient to read or write, but it does the job for a lot of use cases.
Often people write converters. They have their own tracing format, maybe proprietary, maybe open source but something we don’t know about, and it’s very common that people convert to one of the formats we understand, most commonly our protobuf or Chrome JSON formats.
The Perfetto UI is fundamentally a web-based trace visualizer, combining timeline visualization, user-driven selection/aggregation, and SQL queries all in one interface. Because it has the trace processor as a backend, it works with a bunch of different trace formats.
It’s very important to note that even though the Perfetto UI is web-based, everything happens inside your browser and trace data never leaves your system. You can even build it and host it yourself on any static server: we’ve made it extremely easy to do so!
At the start of 2025, we actually moved our whole development to GitHub. In the past, we used to develop on Android and GitHub was just a mirror. That’s no longer the case, GitHub is actually where we develop and take pull requests.
Most of this talk, I’m going to spend actually showing you how you can use the Perfetto UI to debug performance issues on Linux. I don’t want to show you an Android trace which needs a lot of context about how the Android system works and so you think, “oh, that was cool, but I didn’t really understand what was happening.”
So to make this talk more approachable, I wrote a straightforward demo program you can look at yourself! So it’s obviously not a production system but I’ve tried to make it as representative of the sort of issues we use Perfetto for every day.
It’s a Rust program which generates a Julia set and visualizes it over time. The technologies I used: Vulkan, GPU rendering and also multi-threaded CPU computation. So how it works is that computation of various parameters is happening on background threads, and then that’s being passed to the main thread for rendering.
And then, for demonstration purposes, there is a performance bug; rendering should run at 60 FPS, but every so often, the frame rate drops dramatically. Here’s what that looks like:
The code is on GitHub and if you’re interested in following along. The traces are there as well - you don’t have to collect the traces yourself, but you can if you want. All the instructions and information is in the README.
So the first suspicion we may have is that maybe it’s some CPU problem. A lot of engineers I know would reach for perf immediately whenever they see a problem like this. The main reason is that if perf can capture the problem, they can go straight to the line of code without needing to spend time debugging using more complex approaches.</description><content:encoded>&lt;p&gt;I gave a talk at the &lt;a href="https://tracingsummit.org/"&gt;2025 Tracing Summit&lt;/a&gt; last month titled &amp;ldquo;&lt;a href="https://cfp.tracingsummit.org/ts2025/talk/TKVU8W/"&gt;Perfetto: The Swiss Army Knife of Linux Client/Embedded Tracing&lt;/a&gt;&amp;rdquo;. My goal in this talk was to show how Linux kernel, systems and embedded developers can use &lt;a href="https://docs.perfetto.dev"&gt;Perfetto&lt;/a&gt; when debugging and root-causing performance issues in their respective domains. Even though the Perfetto UI is primarily built for viewing &lt;a href="https://perfetto.dev/docs/#why-would-you-use-perfetto-"&gt;Android or Chrome traces&lt;/a&gt;, it is a flexible tool and can be used in many other ways!&lt;/p&gt;
&lt;p&gt;The talk was recorded and is available on &lt;a href="https://www.youtube.com/watch?v=VzTwul2Qb3g"&gt;YouTube&lt;/a&gt;. Taking inspiration from &lt;a href="https://simonwillison.net/"&gt;Simon Willison&lt;/a&gt;, this post is an &lt;a href="https://simonwillison.net/2023/Aug/6/annotated-presentations/"&gt;annotated presentation&lt;/a&gt; containing my slides and detailed notes on them. The talk also has a lot of UI demos: for these, I&amp;rsquo;ll have a screenshot but also a link to the relevant part of the video (videos are unbeatable for UI!).&lt;/p&gt;
&lt;div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%;"&gt;
&lt;iframe style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" src="https://www.youtube.com/embed/VzTwul2Qb3g" title="TS2025 - Perfetto: The Swiss Army Knife of Linux Client/Embedded Tracing" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen&gt;&lt;/iframe&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;p&gt;First, what is Perfetto? Perfetto is fundamentally a suite of tools: it&amp;rsquo;s not just one thing but a bunch of different tools working together to help you debug and root-cause problems. This diagram shows how everything fits together, with the core parts of the Perfetto project in the center.&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/perfetto-swiss-army-03.jpg" alt="diagram of all the pieces of Perfetto, Recording tools, protobuf format, trace processor, Perfetto UI, Python API, Format converters. Chrome JSON, Other profiling formats"&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;p&gt;The recording tools for Perfetto consist of 1) an &lt;a href="https://perfetto.dev/docs/getting-started/in-app-tracing"&gt;SDK for C++ apps&lt;/a&gt; 2) a &lt;a href="https://perfetto.dev/docs/getting-started/system-tracing"&gt;daemon&lt;/a&gt; that can collect data from ftrace, /proc, /sys, and various kernel interfaces 3) another &lt;a href="https://perfetto.dev/docs/concepts/service-model"&gt;daemon&lt;/a&gt; that amalgamates trace data from multiple processes into a single trace file. These tools all speak the Perfetto &lt;a href="https://perfetto.dev/docs/getting-started/converting"&gt;protobuf format&lt;/a&gt;, a high-performance trace format designed to be very efficient to write but not to analyze or consume directly.&lt;/p&gt;
&lt;p&gt;That&amp;rsquo;s where the &lt;a href="https://perfetto.dev/docs/analysis/trace-processor"&gt;trace processor&lt;/a&gt; comes in. It&amp;rsquo;s a C++ library that parses the protobuf format, but also a bunch of other widely used trace formats. It exposes this data via an SQL query interface to any embedding program including &lt;a href="https://perfetto.dev/docs/visualization/perfetto-ui"&gt;Perfetto UI&lt;/a&gt; (which is what most of this talk is about) and also to the &lt;a href="https://perfetto.dev/docs/analysis/trace-processor-python"&gt;Python API&lt;/a&gt; if you want to do ad-hoc scripting or analysis in Python.&lt;/p&gt;
&lt;p&gt;There are also very common tracing/profiling formats used by the Linux community: perf.data, ftrace text format, Firefox profiler format, and many others. Perfetto &lt;a href="https://perfetto.dev/docs/getting-started/other-formats"&gt;supports&lt;/a&gt; quite a few of those directly. There&amp;rsquo;s also the Chrome JSON format (AKA the &lt;a href="https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview?tab=t.0"&gt;Trace Event Format&lt;/a&gt;) which is a simpler interchange format. It&amp;rsquo;s not the most efficient to read or write, but it does the job for a lot of use cases.&lt;/p&gt;
&lt;p&gt;Often people write &lt;a href="https://perfetto.dev/docs/getting-started/converting"&gt;converters&lt;/a&gt;. They have their own tracing format, maybe proprietary, maybe open source but something we don&amp;rsquo;t know about, and it&amp;rsquo;s very common that people convert to one of the formats we understand, most commonly our protobuf or Chrome JSON formats.&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/perfetto-swiss-army-04.jpg" alt="Slide showing Perfetto UI architecture with web-based trace visualizer features"&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;p&gt;The &lt;a href="https://perfetto.dev/docs/visualization/perfetto-ui"&gt;Perfetto UI&lt;/a&gt; is fundamentally a web-based trace visualizer, combining timeline visualization, user-driven selection/aggregation, and SQL queries all in one interface. Because it has the trace processor as a backend, it works with a bunch of different trace formats.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s very important to note that even though the Perfetto UI is web-based, everything happens inside your browser and trace data never leaves your system. You can even &lt;a href="https://perfetto.dev/docs/contributing/ui-getting-started"&gt;build it&lt;/a&gt; and host it yourself on any static server: we&amp;rsquo;ve made it extremely easy to do so!&lt;/p&gt;
&lt;p&gt;At the start of 2025, we actually moved our whole development to GitHub. In the past, we used to develop on Android and GitHub was just a mirror. That&amp;rsquo;s no longer the case, GitHub is actually where we develop and take pull requests.&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/perfetto-swiss-army-05.jpg" alt="Slide introducing the fractal renderer demo program with Vulkan and multi-threading"&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;p&gt;Most of this talk, I&amp;rsquo;m going to spend actually showing you how you can use the Perfetto UI to debug performance issues on Linux. I don&amp;rsquo;t want to show you an Android trace which needs a lot of context about how the Android system works and so you think, &amp;ldquo;oh, that was cool, but I didn&amp;rsquo;t really understand what was happening.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;So to make this talk more approachable, I wrote a &lt;a href="https://github.com/LalitMaganti/fractal-renderer-vk"&gt;straightforward demo program&lt;/a&gt; you can look at yourself! So it&amp;rsquo;s obviously not a production system but I&amp;rsquo;ve tried to make it as representative of the sort of issues we use Perfetto for every day.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s a Rust program which generates a Julia set and visualizes it over time. The technologies I used: &lt;a href="https://vulkano.rs/"&gt;Vulkan&lt;/a&gt;, GPU rendering and also multi-threaded CPU computation. So how it works is that computation of various parameters is happening on background threads, and then that&amp;rsquo;s being passed to the main thread for rendering.&lt;/p&gt;
&lt;p&gt;And then, for demonstration purposes, there is a performance bug; rendering should run at 60 FPS, but every so often, the frame rate drops dramatically. Here&amp;rsquo;s what that looks like:&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/test.avif" alt="Animated visualization of Julia set fractal renderer showing frame rate drops"&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;p&gt;The code is on &lt;a href="https://github.com/LalitMaganti/fractal-renderer-vk"&gt;GitHub&lt;/a&gt; and if you&amp;rsquo;re interested in following along. The traces are there as well - you don&amp;rsquo;t have to collect the traces yourself, but you can if you want. All the instructions and information is in the README.&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/perfetto-swiss-army-06.jpg" alt="Slide titled &amp;ldquo;Suspicion #1: Maybe it&amp;rsquo;s a CPU problem?&amp;rdquo; with perf command examples"&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;p&gt;So the first suspicion we may have is that maybe it&amp;rsquo;s some CPU problem. A lot of engineers I know would reach for perf immediately whenever they see a problem like this. The main reason is that if perf can capture the problem, they can go straight to the line of code without needing to spend time debugging using more complex approaches.&lt;/p&gt;
&lt;p&gt;You can record a perf profile with &lt;code&gt;perf record -k mono -g ./fractal_renderer&lt;/code&gt;. The standard post-processing step which I think a lot of people do would be to &lt;a href="https://github.com/brendangregg/FlameGraph"&gt;generate&lt;/a&gt; an SVG flame graph out of this with &lt;code&gt;perf script | stack-collapse-perf.pl --all | flamegraph.pl &amp;gt; fractal-frame.svg&lt;/code&gt;. Here&amp;rsquo;s how that looks like for our perf profile:&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/fractal.svg" alt="Interactive flame graph showing CPU profiling data with thread names and function call stacks dominated by cos and sin operations"&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;See also the &lt;a href="https://lalitm.com/img/fractal.svg"&gt;interactive version of the profile&lt;/a&gt;&lt;/center&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The flame graph shows the thread names at the bottom, and then stacked above are the call stacks of what the program is doing. The width represents how much time is spent in each function. In this case, the worker threads are spending most of their time in &lt;code&gt;cos&lt;/code&gt; and &lt;code&gt;sin&lt;/code&gt; operations, doing math computation. Exactly what you&amp;rsquo;d expect for this type of program. &lt;em&gt;Aside: Interestingly demangling didn&amp;rsquo;t seem to work for Rust out of the box which I find a bit unusual but I didn&amp;rsquo;t dig too much into why this was.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Looking at this, nothing really stands out. There&amp;rsquo;s no smoking gun that immediately reveals the problem. But here&amp;rsquo;s the fundamental limitation: the flame graph aggregates data across the entire trace, losing the time dimension. The performance problem we&amp;rsquo;re seeing happens every 2-3 seconds - brief drops in an otherwise normally functioning program.&lt;/p&gt;
&lt;p&gt;The flame graph shows me the aggregate, dominated by the correct behavior, making it nearly impossible to spot those occasional problematic moments. So how do I find the places where it&amp;rsquo;s doing the wrong thing?&lt;/p&gt;
&lt;p&gt;Well, that&amp;rsquo;s maybe where Perfetto can help you out a little bit! The thing I find lots of people don&amp;rsquo;t know is that perf actually &lt;em&gt;preserves&lt;/em&gt; timestamp information about when samples were taken: many tools drop this information but Perfetto is pretty good at showing that to you. I just need post-process the trace with &lt;code&gt;perf script &amp;gt; fractal.perftext&lt;/code&gt; to generate a text version of the profile which we can then open in the &lt;a href="https://ui.perfetto.dev"&gt;Perfetto UI&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;My demo talking through how to open the perf profile and navigate it starts at &lt;a href="https://youtu.be/VzTwul2Qb3g?t=551"&gt;9:11&lt;/a&gt; in the video.&lt;/em&gt;&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/screenshot3.png" alt="Perfetto UI screenshot showing perf profile timeline with thread tracks and CPU sample markers across time axis"&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Screenshot from &lt;a href="https://youtu.be/VzTwul2Qb3g?t=590"&gt;9:50&lt;/a&gt; in the video&lt;/center&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The x-axis of what you&amp;rsquo;re seeing is time. And every horizontal line represents a thread: we call these lanes &amp;ldquo;tracks&amp;rdquo;. And each of the small arrowheads on the tracks are CPU samples for the associated thread.&lt;/p&gt;
&lt;p&gt;The behavior of the worker threads over time is really interesting. Most of the lifetime of the program, it&amp;rsquo;s doing continuous computation, basically. And then there&amp;rsquo;s this period of time in the middle where there&amp;rsquo;s this very interesting staircase pattern where it seems like only one thread is running at any one time: we&amp;rsquo;ll want to keep a note of this as this is quite important.&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/screenshot4.png" alt="Perfetto UI screenshot demonstrating area selection feature with timeline selection and flame graph visualization below"&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Screenshot from &lt;a href="https://youtu.be/VzTwul2Qb3g?t=637"&gt;10:37&lt;/a&gt; in the video&lt;/center&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;One very cool thing about Perfetto is that it allows me to quickly generate visualizations of whatever I&amp;rsquo;m selecting on the timeline. We call this &amp;ldquo;area selection&amp;rdquo; and it&amp;rsquo;s where I drag my mouse and select a region both horizontally and vertically. This is on one track but even &lt;em&gt;across&lt;/em&gt; multiple tracks. So in the timeline it shows me the selection I&amp;rsquo;m making at the top, plus a flame graph at the bottom representing the aggregation of the samples in just that time period.&lt;/p&gt;
&lt;p&gt;The key advantage is that I can look at individual regions of time interactively. You can also do this with &lt;code&gt;flamegraph.pl&lt;/code&gt; but you need to pre-filter the data to what you&amp;rsquo;re looking for. This assumes you already know what the problem is before you find it. I always find that a bit counterintuitive. I prefer this view where I can see everything first, then decide &amp;ldquo;I want to look at this specific part in more detail.&amp;rdquo; That&amp;rsquo;s what Perfetto lets me do.&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/screenshot5.png" alt="Perfetto UI screenshot showing enhanced flame graph with zoom, frame hiding, regex search, and bottom-up view features"&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Screenshot from &lt;a href="https://youtu.be/VzTwul2Qb3g?t=751"&gt;12:31&lt;/a&gt; in the video&lt;/em&gt;&lt;/center&gt;&lt;/p&gt;
&lt;p&gt;So now on to the flame graph itself: in the last year, I spent a bunch of time on improving the flame graph visualization in Perfetto UI. At Google, we have an internal tool called pprof (related to but not the same as the open-source one), and I&amp;rsquo;ve always loved the visualization it has. So I worked to make Perfetto&amp;rsquo;s flame graph look and behave very similarly.&lt;/p&gt;
&lt;p&gt;There are a bunch of features here. You can zoom in like most flame graph, but you can also say &amp;ldquo;I only want to look at the stack starting from this point&amp;rdquo; — it gets rid of everything above and starts fresh from there. If I don&amp;rsquo;t want to see a particular function like &lt;code&gt;sin&lt;/code&gt;, I can just hide the frame and it gets merged into its parent. The search is regex-based so I can also just type the specific things I&amp;rsquo;m interested in: it&amp;rsquo;s pretty powerful.&lt;/p&gt;
&lt;p&gt;There&amp;rsquo;s also something I don&amp;rsquo;t think I&amp;rsquo;ve seen in other visualizers (I might be wrong, please do correct me!): what I call &amp;ldquo;bottom up&amp;rdquo; view. Imagine you take all the leaves across your entire program and visualize who&amp;rsquo;s calling into them. If you have a leaf function that&amp;rsquo;s called everywhere in your program but reached from many different places, it&amp;rsquo;ll be split across your flame chart. This is the inverse — you&amp;rsquo;re looking at the leaves and asking &amp;ldquo;who is calling me?&amp;rdquo; This is particularly useful when you&amp;rsquo;re trying to optimize very low-level functions that are always at the leaf level — things like memcpy or hashmap operations.&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/perfetto-swiss-army-07.jpg" alt="Slide titled &amp;ldquo;Suspicion #2: Sleeping on what?&amp;rdquo; discussing need for scheduler trace analysis"&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;p&gt;So our main takeaway is that our worker threads all had gaps in their CPU execution in a staircase pattern. This means the threads weren&amp;rsquo;t actually on the CPU and that&amp;rsquo;s usually a sign that they&amp;rsquo;re sleeping.&lt;/p&gt;
&lt;p&gt;But sleeping on what? Locks? Disk? Network? What exactly is happening? To answer that, I need a scheduler trace to show me the wake-up patterns, who&amp;rsquo;s being scheduled when, what type of sleep threads are in, that sort of thing.&lt;/p&gt;
&lt;p&gt;We recently added support for trace-cmd&amp;rsquo;s text format in Perfetto (&lt;em&gt;aside: &lt;a href="https://github.com/google/perfetto/issues/1819"&gt;there&amp;rsquo;s&lt;/a&gt; an open issue to support the binary format too!&lt;/em&gt;). For this demo, I&amp;rsquo;m collecting sched_switch and sched_waking events with &lt;code&gt;sudo trace-cmd record -e sched:sched_switch -e sched:sched_waking -C mono ./fractal-renderer-vk&lt;/code&gt; and we can open it in the UI once we do &lt;code&gt;trace-cmd report -N &amp;gt; fractal.sched&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;The demo showing off scheduler traces starts at &lt;a href="https://youtu.be/VzTwul2Qb3g?t=916"&gt;15:16&lt;/a&gt; in the video.&lt;/em&gt;&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/screenshot6.png" alt="Perfetto UI screenshot showing scheduler trace with CPU scheduling tracks at top, white regions indicating idle time"&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Screenshot from &lt;a href="https://youtu.be/VzTwul2Qb3g?t=950"&gt;15:49&lt;/a&gt; in the video&lt;/em&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;p&gt;So this is what a scheduler trace looks like. Again as before, the x-axis is time. At the top of the trace, you&amp;rsquo;ve got the CPU scheduling tracks. For each CPU, they tell us what was scheduled on that CPU at each point in time. The white regions are where there&amp;rsquo;s nothing scheduled. As I zoom in, you start to see information like the name of the thread that&amp;rsquo;s scheduled, the TID of the thread, and so on. This is the CPU view of things, looking at it from a CPU perspective.&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/screenshot7.png" alt="Perfetto UI screenshot showing thread state tracks with dark green for running, light green for runnable, and white for interruptible sleep"&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Screenshot from &lt;a href="https://youtu.be/VzTwul2Qb3g?t=1008"&gt;16:48&lt;/a&gt; in the video&lt;/em&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;p&gt;There&amp;rsquo;s also a thread perspective on scheduling: what we call this &amp;ldquo;thread state&amp;rdquo;. This shows the scheduling state of each thread at every point in time. Dark green represents the thread running, light green represents runnable (the thread is on the runqueue so it&amp;rsquo;s eligible to run, but the scheduler hasn&amp;rsquo;t actually let it run yet), and white represents interruptible sleep (S sleep). There are also orange regions for uninterruptible sleep (D sleep), though that doesn&amp;rsquo;t show up much in this trace.&lt;/p&gt;
&lt;p&gt;You can again see a very clear staircase-like pattern. Again, only one thread seems to be running at any one time. You&amp;rsquo;re maybe getting the sense of what the problem might be at this point.&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/screenshot8.png" alt="Perfetto UI screenshot showing area selection on CPU track with tables displaying time spent by each thread"&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Screenshot from &lt;a href="https://youtu.be/VzTwul2Qb3g?t=1063"&gt;17:43&lt;/a&gt; in the video&lt;/em&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;p&gt;Like with the perf visualization, you can do area selections here too. I can select a region on a CPU and get tables showing time spent by each thread (shown in the screenshot above). I can also do this for thread state, you can also see that runnable time is basically negligible compared to running and sleeping, which is where most of the time is being spent.&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/screenshot9.png" alt="Perfetto UI screenshot showing scheduler visualizations including run queue length and active CPU count metrics"&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Screenshot from &lt;a href="https://youtu.be/VzTwul2Qb3g?t=1092"&gt;18:12&lt;/a&gt; in the video&lt;/em&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;p&gt;There are also scheduler-specific visualizations like run queue length and active CPU count. You can see in the problematic region, the active CPU count also went down, which makes sense.&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/perfetto-swiss-army-08.jpg" alt="Slide titled &amp;ldquo;Suspicion #3: What is the program doing?&amp;rdquo; discussing need for application-level visibility"&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;p&gt;So the scheduler trace shows when threads are sleeping, but it&amp;rsquo;s not telling us why. What was the program doing in that region? What code was it running? The sequential pattern suggests some sort of serialization—something is causing only one thread to run at a time. But we need application-level visibility.&lt;/p&gt;
&lt;p&gt;Since this program was written in Rust, I just used the off-the-shelf &lt;a href="https://docs.rs/tracing/latest/tracing/"&gt;&lt;code&gt;tracing&lt;/code&gt;&lt;/a&gt; and &lt;a href="https://docs.rs/tracing-perfetto/latest/tracing_perfetto/"&gt;&lt;code&gt;tracing-perfetto&lt;/code&gt;&lt;/a&gt; crates; I did have to make some small &lt;a href="https://github.com/LalitMaganti/tracing-perfetto"&gt;modifications&lt;/a&gt; to tracing-perfetto that I&amp;rsquo;m hoping to upstream. These output a Perfetto trace without needing to use the Perfetto SDK. These libraries are also maintained by others: we don&amp;rsquo;t have any hand in them.&lt;/p&gt;
&lt;p&gt;All I needed to do was integrate these into my program and then add a command line switch to write out the collected trace to a file. So I just do &lt;code&gt;./fractal_renderer --trace fractal.pftrace&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;My demo for app tracing starts at &lt;a href="https://youtu.be/VzTwul2Qb3g?t=1177"&gt;19:37&lt;/a&gt; in the video.&lt;/em&gt;&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/screenshot10.png" alt="Perfetto UI screenshot showing app trace with userspace instrumentation slices on thread tracks representing program activity"&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Screenshot from &lt;a href="https://youtu.be/VzTwul2Qb3g?t=1206"&gt;20:06&lt;/a&gt; in the video&lt;/em&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;p&gt;Looking at the app trace: as before x-axis is time and each of the tracks represents a thread. Instead of scheduling activity or CPU stack samples, this time the tracks is userspace instrumentation of the program itself. Each of these rectangles is a named period of time representing what the program was doing at that time.&lt;/p&gt;
&lt;p&gt;There are lots of different names for these in the tracing world (e.g. spans, intervals) but we call these &amp;ldquo;slices&amp;rdquo;. The main thread is rendering frames as you would expect and the workers are each computing tiles of that frame, which eventually feed back to the main thread and sync to the GPU.&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/screenshot11.png" alt="Perfetto UI screenshot showing flow visualization with causal links between render frame and worker thread operations"&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Screenshot from &lt;a href="https://youtu.be/VzTwul2Qb3g?t=1425"&gt;23:42&lt;/a&gt; in the video&lt;/em&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;p&gt;There&amp;rsquo;s also this thing called flows, which shows the causal links between different pieces. Render frame is calling into all these places and causing them to happen. It&amp;rsquo;s sort of similar to wakeup graphs but for user space: basically, this is what caused me to start running this function.&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/screenshot12.png" alt="Perfetto UI screenshot zoomed into problematic region showing 1.8 second duration for update adaptive quality operation"&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Screenshot from &lt;a href="https://youtu.be/VzTwul2Qb3g?t=1431"&gt;23:51&lt;/a&gt; in the video&lt;/em&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;p&gt;So you can see very clearly there&amp;rsquo;s a normal region and then a region where things are taking 1.8 seconds: almost certainly the cause of the frame drops.&lt;/p&gt;
&lt;p&gt;And if we look at the slice in question, it seems to be doing something called &amp;ldquo;update adaptive quality.&amp;rdquo; Basically, I wrote some code to dynamically change the rendering quality based on frame rate. If I&amp;rsquo;m running faster, I can render at higher quality. If I&amp;rsquo;m running slower, I can do lower quality. That&amp;rsquo;s what this adaptive quality thing is supposed to do.&lt;/p&gt;
&lt;p&gt;But clearly something has gone wrong. I&amp;rsquo;m causing frame drops because of updates to adaptive quality. A little bit ironic, to say the least. Now we know what the program is actually doing during that time span.&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/perfetto-swiss-army-09.jpg" alt="Slide titled &amp;ldquo;Putting it all together: The merged trace&amp;rdquo; explaining trace merging feature"&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;p&gt;So now we&amp;rsquo;ve looked at three different sources of debugging data separately. In perf, we got told there are few or no CPU samples and weird staircase patterns. In ftrace, we saw only one worker seems to be active and the rest are sleeping in interruptible sleep. And in app tracing, we see it&amp;rsquo;s because of adaptive quality updates that workers are working on, and they shouldn&amp;rsquo;t be doing it this way.&lt;/p&gt;
&lt;p&gt;Obviously, the theory is that it&amp;rsquo;s all the same problem. But we can confirm this theory with a very new (and still experimental) feature of the UI: trace merging.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note: as this part of Perfetto is still experimental, if you want to try it yourself, you need to go to plugins and enable the &amp;ldquo;MultiTraceOpen&amp;rdquo; plugin. Also, unlike I what say in the talk, you do &lt;strong&gt;not&lt;/strong&gt; need to be on Autopush as all the features I showed in my talk are now available in Stable.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;The demo showing off merged traces starts at &lt;a href="https://youtu.be/VzTwul2Qb3g?t=1472"&gt;24:32&lt;/a&gt; in the video.&lt;/em&gt;&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/screenshot13.png" alt="Perfetto UI screenshot showing merged trace with CPU scheduling tracks, stack samples, and app instrumentation on single timeline"&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Screenshot from &lt;a href="https://youtu.be/VzTwul2Qb3g?t=1544"&gt;25:44&lt;/a&gt; in the video&lt;/em&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;p&gt;This is now the merged trace file containing all the different information. You can see the CPU scheduling tracks like we had in the scheduler trace, the stack samples like we had in the perf trace, and the app instrumentation, all beside each other on one timeline.
You can very clearly see the adaptive quality update running, then this period where it ran, and then it was done. It&amp;rsquo;s very cool to be able to see the pattern of how my program is sleeping and where and what it was running on one timeline.&lt;/p&gt;
&lt;p&gt;The thing is, you&amp;rsquo;ve always been able to do this with Perfetto if you collect a Perfetto trace with all of these integrated. The new capability is that this is now being brought to traces you didn&amp;rsquo;t collect with Perfetto. Collect it with whatever you like, and we&amp;rsquo;ll still manage to do this visualization. That&amp;rsquo;s the new capability we have.&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/screenshot14.png" alt="Perfetto UI screenshot showing query interface with pivot tables and filter options for trace data analysis"&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Screenshot from &lt;a href="https://youtu.be/VzTwul2Qb3g?t=1798"&gt;29:58&lt;/a&gt; in the video&lt;/em&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;p&gt;There&amp;rsquo;s also a query interface which we&amp;rsquo;ve been building out recently and there are some pretty powerful things you can do with these tables. As well as the flat tables of data, there&amp;rsquo;s also a more dynamic pivot table and if I click the arrow on the left, I can get into a detailed filter table, similar to a spreadsheet but optimize for things people want to do on traces.&lt;/p&gt;
&lt;p&gt;For example, by doing an area select, I can first get a list of all the events that happened during a time region. Then using the table I can filter for things - say I only care about slices longer than some duration, like 319 microseconds for whatever reason. I can click and add a filter for things greater than this.&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/screenshot15.png" alt="Perfetto UI screenshot demonstrating Show Debug Track feature with filtered events visualized as timeline track"&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Screenshot from &lt;a href="https://youtu.be/VzTwul2Qb3g?t=1811"&gt;30:11&lt;/a&gt; in the video&lt;/em&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;p&gt;There&amp;rsquo;s also a feature called &amp;ldquo;Show Debug Track&amp;rdquo; that&amp;rsquo;s also very powerful. The table shows rows with timestamped duration information, and this feature lets you visualize that data as a track on the timeline. It adds a track at the top showing the regions of time where these events happened—in this case, where ComputeTile took longer than a certain threshold.&lt;/p&gt;
&lt;p&gt;This is particularly useful for correlation analysis. For example, in Android, we&amp;rsquo;re often looking at system A and trying to understand its effect on system B. We find all the places where one thing is slow, then look for correlations. Being able to see a track in the UI where you can quickly have context and say &amp;ldquo;oh, during this period of time, this other thing was happening&amp;rdquo; is invaluable. It&amp;rsquo;s probably one of our most-used features.&lt;/p&gt;
&lt;p&gt;You can also copy the SQL query from these tables and start doing your own aggregations on top of it. This eases the burden of starting with a completely blank canvas. Instead of wondering &amp;ldquo;where do I even start querying my data? What tables is my data in?&amp;rdquo;, the UI gives you a starting query that you can build on without needing to write something from scratch.&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/perfetto-swiss-army-10.jpg" alt="Slide titled &amp;ldquo;The root cause&amp;rdquo; summarizing findings about dynamic quality updates causing frame drops"&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;p&gt;So the dynamic quality updates were stopping the world. Perf profiling showed the problem, scheduler traces found the sleeping pattern, app tracing confirmed it was the quality adjustment code, and the single timeline view let me see everything happening at once.&lt;/p&gt;
&lt;p&gt;Interestingly, I tried to fix this by removing the lock contention—which I thought was the bug I had introduced. But it turns out I shouldn&amp;rsquo;t have been doing this code in the workers in the first place. Even after removing the lock contention, just the CPU activity of doing that work was enough to cause frame drops. The right solution was to move it to a background thread. As part of debugging this for the demo, I discovered something even better that I could be doing.&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/perfetto-swiss-army-11.jpg" alt="Slide titled &amp;ldquo;Perfetto in the Open-Source Community&amp;rdquo; listing projects using Perfetto including Mesa, VizTracer, pthread_trace, magic-trace, sched-analyzer, and systing"&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://docs.perfetto.dev"&gt;Android and Chrome&lt;/a&gt; are our bread and butter—that&amp;rsquo;s what we officially support as a team, and why Google staffs us. But there are many other interesting uses.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://docs.mesa3d.org/perfetto.html"&gt;Mesa&lt;/a&gt; uses Perfetto as one of its tracing systems. One thing I could have shown is collecting a Mesa trace alongside all the other traces we looked at—you can actually see what the GPU is doing at the same time, which would have been very cool, but I just didn&amp;rsquo;t have time.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://github.com/gaogaotiantian/viztracer"&gt;VizTracer&lt;/a&gt; is function tracing for Python, similar to uftrace, but you don&amp;rsquo;t have to recompile anything or do anything special.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://github.com/dsharlet/pthread_trace"&gt;pthread_trace&lt;/a&gt; is for visualizing pthread mutex contention. The author has a very efficient way of doing this and writes protobuf using heavy use of constexpr to make it very low overhead. It&amp;rsquo;s a very interesting project.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://github.com/janestreet/magic-trace"&gt;magic-trace&lt;/a&gt; uses Intel Processor Trace for function-level tracing at the processor level with lower overhead. They wrote a converter from that to the Perfetto format so you can visualize that data in Perfetto.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://github.com/qais-yousef/sched-analyzer"&gt;Qais Yousef&amp;rsquo;s sched-analyzer&lt;/a&gt; enriches Perfetto traces with scheduler internals. It&amp;rsquo;s a very cool project that I find particularly interesting.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://gist.github.com/johnstultz-work/0ec4974e0929c4707bfd89c876ae4735"&gt;John Stultz&amp;rsquo;s all-in-one Perfetto recording script&lt;/a&gt; for kernel developers addresses a common complaint: &amp;ldquo;Perfetto is so complicated, I don&amp;rsquo;t know what events I want to record.&amp;rdquo; He just wrote a script that configures everything for you.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Finally, &lt;a href="https://josefbacik.github.io/kernel/systing/debugging/2025/05/08/systing.html"&gt;Josef Bacik&amp;rsquo;s systing&lt;/a&gt; is a bit experimental but fascinating. He re-implemented tracing daemons on top of BPF instead of Perfetto&amp;rsquo;s native implementation, combining BPF-based tracing with perf stack traces in a single binary. He has a blog post explaining why. I thought it was a fascinating use of Perfetto.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/perfetto-swiss-army-12.jpg" alt="Slide encouraging users to try the demo program and record their own traces"&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;p&gt;If you want to try this yourself, you can use the &lt;a href="https://github.com/LalitMaganti/fractal-renderer-vk"&gt;demo program I&amp;rsquo;ve provided&lt;/a&gt;. But even better: record traces on your own programs. Open scheduler traces and perf at the same time. Instrument your program, convert it to Perfetto format, and visualize everything together.&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/perfetto-swiss-army-13.jpg" alt="Slide promoting comprehensive tutorial for converting ad-hoc timestamped data to Perfetto format"&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;p&gt;If you want to convert ad-hoc timestamped data to Perfetto, we wrote a &lt;a href="https://perfetto.dev/docs/getting-started/converting"&gt;comprehensive tutorial&lt;/a&gt; with Python snippets for everything you might want to visualize. It covers all the features I showed and how to write Python code to generate them. We have a library for writing these traces: besides this one library, you don&amp;rsquo;t need to install anything else. You can go ahead and convert your own data to Perfetto.&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/perfetto-swiss-army-14.jpg" alt="Slide welcoming contributions and pull requests to the Perfetto project"&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;p&gt;We&amp;rsquo;re very happy to accept contributions and review pull requests pretty quickly. We&amp;rsquo;ve had a lot of open-source contributors over the years and have been quite lucky with some very high-quality contributions. If you want to contribute yourself or have a feature you feel is missing, send it our way.&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;img src="https://lalitm.com/img/perfetto-swiss-army-15.jpg" alt="Final slide with contact information and links to demo repo, documentation, and Perfetto UI"&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Demo repo: &lt;a href="https://github.com/LalitMaganti/fractal-renderer-vk"&gt;github.com/LalitMaganti/fractal-renderer-vk&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Learn more: &lt;a href="https://docs.perfetto.dev"&gt;docs.perfetto.dev&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Perfetto UI: &lt;a href="https://ui.perfetto.dev"&gt;ui.perfetto.dev&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Contact: &lt;a href="mailto:lalitm@google.com"&gt;lalitm@google.com&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item><item><title>TIL: `will-change` and `isolation` CSS properties</title><link>https://lalitm.com/til-will-change-and-isolation-css-properties/</link><pubDate>Fri, 24 Oct 2025 00:20:00 +0100</pubDate><guid>https://lalitm.com/til-will-change-and-isolation-css-properties/</guid><description>The Perfetto UI is a fascinating project to work on because it often faces performance problems which you wouldn’t see in more “normal” webapps. I learn about all sorts of weird web features by reviewing PRs for the UI.
Two such features I just learned about:
will-change (PR): a hint, to be used sparingly, to tell the browser that a certain property of a DOM element will change in the near future. isolation (PR): I feel MDN didn’t do a great job of explaining so I asked Claude which gave a much more useful answer: isolation is a CSS property that creates a new stacking context for an element. Think of a stacking context as a self-contained z-index universe. Elements within one stacking context can layer on top of each other, but their z-index values only matter relative to siblings within that same context.</description><content:encoded>&lt;p&gt;The Perfetto UI is a fascinating project to work on because it often faces performance problems which you wouldn&amp;rsquo;t see in more &amp;ldquo;normal&amp;rdquo; webapps. I learn about all sorts of weird web features by reviewing PRs for the UI.&lt;/p&gt;
&lt;p&gt;Two such features I just learned about:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/will-change"&gt;will-change&lt;/a&gt; (&lt;a href="https://github.com/google/perfetto/pull/3350/files#diff-c57fa71e0c282ce81f65b10226043f6d89c4105afd3f5ec5813b8d9d5e034101R128"&gt;PR&lt;/a&gt;): a hint, to be used sparingly, to tell the browser that a certain property of a DOM element will change in the near future.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/isolation"&gt;isolation&lt;/a&gt; (&lt;em&gt;&lt;a href="https://github.com/google/perfetto/pull/3381/files#diff-c57fa71e0c282ce81f65b10226043f6d89c4105afd3f5ec5813b8d9d5e034101R119"&gt;PR&lt;/a&gt;&lt;/em&gt;):
I feel MDN didn&amp;rsquo;t do a great job of explaining so I asked Claude which gave a much more useful answer:
&lt;blockquote&gt;
&lt;p&gt;isolation is a CSS property that creates a new stacking context for an element. Think of a stacking context as a self-contained z-index universe. Elements within one stacking context can layer on top of each other, but their z-index values only matter relative to siblings within that same context.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item></channel></rss>