commit b379f344ef613be308750ed514ce30493e875220
parent e36b236a4a8057302158fc395c8cf9988507cc72
Author: Andrew Laack <andrew@laack.co>
Date: Sun, 11 Oct 2026 16:19:17 -0500
Links
Diffstat:
2 files changed, 21 insertions(+), 20 deletions(-)
diff --git a/posts/site_wip/basic-software-profiling-cpu-usage.html b/posts/site_wip/basic-software-profiling-cpu-usage.html
@@ -98,7 +98,10 @@
<link rel="stylesheet" href="style.css" />
</head>
<body>
-<p>TODOS: - since we support http(s) we mustn’t hardcode file paths. - review the ending stuff - formatting for all the preformatted sections</p>
+<p>TODOS:</p>
+<ul>
+<li>review the ending stuff</li>
+</ul>
<h1 id="basic-software-profiling-cpu-usage">Basic Software Profiling: CPU Usage</h1>
<p>Collectively, we waste trillions of CPU cycles every day because software isn’t profiled frequently. I believe this is an educational problem.</p>
<p>This post will explain how you can find the parts of a program hogging the most CPU time. The post will focus on compiled programs, but the core ideas can be applied to interpreted programs.</p>
@@ -107,7 +110,7 @@
<p><a href="https://github.com/brendangregg/FlameGraph">Flamegraph</a> is a suite of tools for generating flamegraphs, a type of graph designed for the visualization of performance data.</p>
<h2 id="reading-a-flamegraph">Reading a Flamegraph</h2>
<p>Take a look at the flamegraph below and try to understand the performance characteristics of the program:</p>
-<object data="https://blog.laack.co/images/ex1-fg.svg" type="image/svg+xml" width="100%">
+<object data="/images/ex1-fg.svg" type="image/svg+xml" width="100%">
</object>
<details>
<summary>
@@ -195,18 +198,18 @@ Source code for the program that generated this flamegraph
<pre><code>perf stat ./ex1</code></pre>
<pre><code> Performance counter stats for './ex1':
- 0 context-switches:u # 0.0 cs/sec cs_per_second
- 0 cpu-migrations:u # 0.0 migrations/sec migrations_per_second
- 132 page-faults:u # 4.1 faults/sec page_faults_per_second
- 32,436.48 msec task-clock:u # nan CPUs CPUs_utilized
- 356,775 branch-misses:u # 0.0 % branch_miss_rate (88.89%)
- 63,706,083,988 branches:u # 1964.0 M/sec branch_frequency (88.89%)
- 134,126,037,336 cpu-cycles:u # 4.1 GHz cycles_frequency (88.89%)
- 300,951,617,557 instructions:u # 2.2 instructions insn_per_cycle (88.89%)
+ 0 context-switches:u # 0.0 cs/sec cs_per_second
+ 0 cpu-migrations:u # 0.0 migrations/sec migrations_per_second
+ 132 page-faults:u # 4.1 faults/sec page_faults_per_second
+ 32,436.48 msec task-clock:u # nan CPUs CPUs_utilized
+ 356,775 branch-misses:u # 0.0 % branch_miss_rate (88.89%)
+ 63,706,083,988 branches:u # 1964.0 M/sec branch_frequency (88.89%)
+ 134,126,037,336 cpu-cycles:u # 4.1 GHz cycles_frequency (88.89%)
+ 300,951,617,557 instructions:u # 2.2 instructions insn_per_cycle (88.89%)
TopdownL1 # 4.4 % tma_backend_bound
- # 61.4 % tma_bad_speculation (88.89%)
- # 0.0 % tma_frontend_bound (77.78%)
- # 34.2 % tma_retiring (88.89%)
+ # 61.4 % tma_bad_speculation (88.89%)
+ # 0.0 % tma_frontend_bound (77.78%)
+ # 34.2 % tma_retiring (88.89%)
32.440411262 seconds time elapsed
@@ -320,7 +323,7 @@ Performance counter stats for 'amfora lf.txt':
63.894262000 seconds user
8.207151000 seconds sys</code></pre>
<p>That’s a lot slower for Amfora. Let’s look at a flamegraph for this.</p>
-<object data="https://blog.laack.co/images/amfora-before.svg" type="image/svg+xml" width="100%">
+<object data="/images/amfora-before.svg" type="image/svg+xml" width="100%">
</object>
<p>So 68.34% samples occurred while executing the GC, that’s a bit surprising, even given how awful garbage collectors are. We also see that 25.47% of the time, most of the remaining time, is spent in the RenderGemini function. Of this, most of it is spent on concatstring3, a function under the hood that’s used to concatenate strings.</p>
<p>Here’s where that’d be used in the function:</p>
@@ -363,7 +366,7 @@ buf += strings.TrimSuffix(lines[i], "\r") + "\r\n"</code></p
1.193871000 seconds user
0.039062000 seconds sys</code></pre>
<p>Much better, that’s now using 32x less cycles, and is far faster than before.</p>
-<object data="https://blog.laack.co/images/amfora-after.svg" type="image/svg+xml" width="100%">
+<object data="/images/amfora-after.svg" type="image/svg+xml" width="100%">
</object>
<p>Looking again at the flamegraph, we see the RenderGemini function is now mostly performing word wrapping, and the GC is only utilizing the CPU during 16.48% of our samples, much better.</p>
<p>We can go deeper into this if we’d like, but there are now 3 ~equally costly groupings, and as performance becomes more diffuse, optimizations will generally have a smaller amount of impact on perf, so we can leave this where it is.</p>
diff --git a/posts/wip/basic-software-profiling-cpu-usage.md b/posts/wip/basic-software-profiling-cpu-usage.md
@@ -1,8 +1,6 @@
TODOS:
-- since we support http(s) we mustn't hardcode file paths.
- review the ending stuff
-- formatting for all the preformatted sections
# Basic Software Profiling: CPU Usage
@@ -20,7 +18,7 @@ This post will explain how you can find the parts of a program hogging the most
Take a look at the flamegraph below and try to understand the performance characteristics of the program:
-<object data="https://blog.laack.co/images/ex1-fg.svg" type="image/svg+xml" width="100%"></object>
+<object data="/images/ex1-fg.svg" type="image/svg+xml" width="100%"></object>
<details>
<summary>Source code for the program that generated this flamegraph</summary>
@@ -299,7 +297,7 @@ perf stat amfora lf.gmi
That's a lot slower for Amfora. Let's look at a flamegraph for this.
-<object data="https://blog.laack.co/images/amfora-before.svg" type="image/svg+xml" width="100%"></object>
+<object data="/images/amfora-before.svg" type="image/svg+xml" width="100%"></object>
So 68.34% samples occurred while executing the GC, that's a bit surprising, even given how awful garbage collectors are. We also see that 25.47% of the time, most of the remaining time, is spent in the RenderGemini function. Of this, most of it is spent on concatstring3, a function under the hood that's used to concatenate strings.
@@ -355,7 +353,7 @@ perf stat amfora lf.gmi
Much better, that's now using 32x less cycles, and is far faster than before.
-<object data="https://blog.laack.co/images/amfora-after.svg" type="image/svg+xml" width="100%"></object>
+<object data="/images/amfora-after.svg" type="image/svg+xml" width="100%"></object>
Looking again at the flamegraph, we see the RenderGemini function is now mostly performing word wrapping, and the GC is only utilizing the CPU during 16.48% of our samples, much better.