blog

Personal blog
git clone git://git.laack.co/blog.git
Log | Files | Refs

feed.xml (68396B)


      1 <?xml version="1.0" encoding="UTF-8"?>
      2 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
      3 <channel>
      4 <title>Andrew's Blog</title>
      5 <link>gemini://blog.laack.co</link>
      6 <description>Latest posts from Andrew's blog</description>
      7 <language>en-us</language>
      8 <managingEditor>andrew@laack.co</managingEditor>
      9 <webMaster>andrew@laack.co</webMaster>
     10 <lastBuildDate>Sat, 17 Oct 2026 15:51:38 -0500</lastBuildDate>
     11 <atom:link href="gemini://blog.laack.co/feed.xml" rel="self" type="application/rss+xml"/>
     12 <item>
     13 <title><![CDATA[Basic Software Profiling: CPU Usage]]></title>
     14 <link>gemini://blog.laack.co/basic-software-profiling-cpu-usage.gmi</link>
     15 <description><![CDATA[<p>Software today is much slower than it should be. I believe this is, in part, because most software developers do not understand performance.</p>
     16 <p>An easily explainable aspect of performance is profiling, and in this post I’ll discuss the basics of if. I’ll be focusing on compiled programs, but the core ideas may be applied to interpreted programs too.</p>
     17 <h2 id="tools">Tools</h2>
     18 <p><a href="https://en.wikipedia.org/wiki/Perf_%28Linux%29">Perf</a> is a suite of tools for program profiling on Linux. We will mainly use it to collect aggregate performance metrics and call stack information. Analogous tools exist for other Free operating systems, and many bespoke tools exist for interpreted programs.</p>
     19 <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. I’ll be using my <a href="https://git.laack.co/flamegraph">fork of flamegraph</a> which doesn’t add j***s***** to generated SVGs, but apart from that they function identically.</p>
     20 <h2 id="reading-a-flamegraph">Reading a Flamegraph</h2>
     21 <p>Look at the flamegraph and try to understand the performance characteristics of the program:</p>
     22 <object data="/images/ex1-fg.svg" type="image/svg+xml" width="100%">
     23 </object>
     24 <details>
     25 <summary>
     26 Source code for the program that generated this flamegraph
     27 </summary>
     28 <pre class="cpp"><code>uint32_t square(uint32_t input) {
     29     return input * input;
     30 }
     31 
     32 // helper function to show stack depths
     33 uint32_t squareHelper(uint32_t input) {
     34     uint32_t x = 100 * 100;
     35     return square(input);
     36 }
     37 
     38 uint32_t factorial(uint32_t input) {
     39     uint32_t acc = 1;
     40 
     41     while(input &gt; 1) {
     42         acc *= input;
     43         input -= 1;
     44     }
     45     return acc;
     46 }
     47 
     48 int main() {
     49 
     50     uint32_t ub = std::sqrt(UINT32_MAX);
     51 
     52     for(uint32_t i = 0; i &lt; ub; ++i) {
     53         for(uint32_t x = 0; x &lt; 100000; ++x) {
     54             square(i);
     55         }
     56 
     57         for(uint32_t x = 0; x &lt; 100000; ++x) {
     58             squareHelper(i);
     59         }
     60 
     61         for(uint32_t x = 0; x &lt; 20000; ++x) {
     62             factorial(x % 10);
     63         }
     64     }
     65 }</code></pre>
     66 </details>
     67 <p>The amount of time spent with the <code>main</code> function on the call stack is represented by the width of its bar.</p>
     68 <p>Notice how there are multiple bars that say <code>square</code>. This is because we execute <code>square</code> at different call stack depths, and the width of each bar is proportional to the amount of time we spent with <code>square</code> on the call stack at a given stack depth.</p>
     69 <p>Given how the widths are calculated, we can deduce the top-down width of a bar is how much time the program spent executing a specific function. In the case of <code>squareHelper</code> and <code>square</code>, we see we spent more time executing <code>squareHelper</code> than <code>square</code>, evidenced by the fact that from a top-down view, <code>squareHelper</code> is wider.</p>
     70 <p>The astute among you might’ve noticed <code>square</code> and <code>squareHelper</code> seem to have been executed a few times outside of the main loop. This is due to how <code>perf</code> calculates the stack depth. The specifics of this are more in the weeds than we’ll discuss here, but it shouldn’t meaningfully impact the high level information that can be obtained from a flamegraph.</p>
     71 <h2 id="perf">Perf</h2>
     72 <p>I’ve been loose with my words in terms of the specific data being displayed by the flamegraph. The command I used to generate the data for the flamegraph doesn’t technically track the amount of time spent with a function on the stack at a given depth, we are instead tracking the number of on-CPU samples taken with the function on the top of the call stack. This distinction is important because things like blocking I/O will not be reflected in our timings.</p>
     73 <p>This is the command I ran to generate the data:</p>
     74 <pre class="bash"><code>perf record -g ./ex1</code></pre>
     75 <p>The <code>perf record</code> command is used to run a command and record its performance profile, which is written to the <code>perf.data</code> file. By default, <code>perf record</code> will sample at 1000Hz while the program is on-CPU. The final option, <code>-g</code>, is used to specify we are interested in having the call stack included in our data.</p>
     76 <p>To view aggregate information about the data in the <code>perf.data</code> file we can run:</p>
     77 <pre class="bash"><code>perf report -g
     78 
     79 +  100.00%     0.00%  ex1      ex1                   [.] _start
     80 +  100.00%     0.00%  ex1      libc.so.6             [.] __libc_start_main
     81 +  100.00%     0.00%  ex1      libc.so.6             [.] call_init (inlined)
     82 +  100.00%     0.00%  ex1      libc.so.6             [.] 0x00007f6302a27781
     83 +   99.79%    39.46%  ex1      ex1                   [.] main
     84 +   34.97%    19.94%  ex1      ex1                   [.] squareHelper(unsigned int)
     85 +   29.99%    19.90%  ex1      ex1                   [.] square(unsigned int)
     86 +   21.61%    20.69%  ex1      ex1                   [.] factorial(unsigned int)
     87 ...</code></pre>
     88 <p>If you are interested in information about which functions are calling each other, and the associated on-CPU times, you can run this command:</p>
     89 <pre class="bash"><code>perf report -g --stdio
     90 
     91 ...
     92 
     93 |--88.87%--main
     94 |          |
     95 |          |--19.84%--squareHelper(unsigned int)
     96 |          |          |
     97 |          |           --4.99%--square(unsigned int)
     98 |          |
     99 |          |--19.55%--factorial(unsigned int)
    100 |          |
    101 |           --10.07%--square(unsigned int)
    102 |
    103 |--5.02%--squareHelper(unsigned int)
    104 |
    105 |--4.98%--square(unsigned int)
    106 |
    107 --1.13%--factorial(unsigned int)
    108 ...</code></pre>
    109 <p>I often find the <code>--stdio</code> command difficult to read because the report can get wide for non-trivial programs, and horizontal navigation in the terminal is unergonomic.</p>
    110 <p>The final command worth mentioning is:</p>
    111 <pre><code>perf stat ./ex1
    112 
    113  Performance counter stats for &#39;./ex1&#39;:
    114 
    115                  0      context-switches:u              #      0.0 cs/sec  cs_per_second
    116                  0      cpu-migrations:u                #      0.0 migrations/sec  migrations_per_second
    117                132      page-faults:u                   #      4.1 faults/sec  page_faults_per_second
    118          32,436.48 msec task-clock:u                    #      nan CPUs  CPUs_utilized
    119            356,775      branch-misses:u                 #      0.0 %  branch_miss_rate           (88.89%)
    120     63,706,083,988      branches:u                      #   1964.0 M/sec  branch_frequency       (88.89%)
    121    134,126,037,336      cpu-cycles:u                    #      4.1 GHz  cycles_frequency         (88.89%)
    122    300,951,617,557      instructions:u                  #      2.2 instructions  insn_per_cycle  (88.89%)
    123          TopdownL1                                      #      4.4 %  tma_backend_bound
    124                                                         #     61.4 %  tma_bad_speculation        (88.89%)
    125                                                         #      0.0 %  tma_frontend_bound         (77.78%)
    126                                                         #     34.2 %  tma_retiring               (88.89%)
    127 
    128       32.440411262 seconds time elapsed
    129 
    130       32.234190000 seconds user
    131        0.002939000 seconds sys</code></pre>
    132 <p>Which provides high level information about the program’s entire execution.</p>
    133 <p>This is the command I run most frequently when validating optimizations that target functions making up a sizeable percentage of the program’s CPU usage. If the program is uniformly expensive across many functions, <code>perf stat</code> is less useful than a full report / flamegraph.</p>
    134 <h2 id="case-study">Case Study</h2>
    135 <h3 id="amfora">Amfora</h3>
    136 <p><a href="https://github.com/makew0rld/amfora">Amfora</a> is a fancy terminal-based Gemini protocol browser with syntax highlighting. Gemini is a text-based protocol which primarily distributes <a href="https://geminiprotocol.net/docs/gemtext.gmi">gemtext</a> documents. These documents use a similar syntax to markdown, but it’s slightly simpler. I chose to profile this program because software in the Gemini ecosystem is often simple to understand, making it great for educational use cases.</p>
    137 <p>When I start profiling software I often find it useful to use an oracle to understand what’s possible. An oracle in this context is a program that performs comparable tasks with decent performance characteristics. I chose <a href="https://git.laack.co/foreseen/">Foreseen</a>, a Gemini protocol browser I developed, as the oracle because it fulfils both criteria.</p>
    138 <p>I like to start by searching for worst case performance scenarios. Worst cases are often an amplification of an average case, so by improving worst case performance we can often improve the average case.</p>
    139 <p>To start our quest to find worse case scenarios for Amfora, we’ll load a large text file from disk, killing the program once the first lines of text are drawn in the terminal. Since neither browser supports text streaming, they both have to load and parse the document and then send text to the terminal, making this is a fair comparison. To generate a baseline document I executed the following Python code:</p>
    140 <pre class="python"><code>with open(&quot;lf.txt&quot;, &quot;w&quot;) as f:
    141     for i in range(0,200000):
    142         f.write(str(i) + &quot;\n&quot;)</code></pre>
    143 <p>The resulting file was ~1.3MB in size. I then ran both programs killing each program with Ctrl-C at first draw.</p>
    144 <pre><code>perf stat amfora lf.txt
    145 
    146 Performance counter stats for &#39;amfora lf.txt&#39;:
    147 
    148                  0      context-switches:u               #      0.0 cs/sec  cs_per_second
    149                  0      cpu-migrations:u                 #      0.0 migrations/sec  migrations_per_second
    150              2,742      page-faults:u                    #   9306.7 faults/sec  page_faults_per_second
    151             294.63 msec task-clock:u                     #      nan CPUs  CPUs_utilized
    152          1,052,499      branch-misses:u                  #      0.2 %  branch_miss_rate           (90.02%)
    153        575,712,764      branches:u                       #   1954.1 M/sec  branch_frequency       (89.14%)
    154        955,922,330      cpu-cycles:u                     #      3.2 GHz  cycles_frequency         (87.42%)
    155      2,669,651,845      instructions:u                   #      2.8 instructions  insn_per_cycle  (88.36%)
    156          TopdownL1                                       #      6.7 %  tma_backend_bound
    157                                                          #     24.9 %  tma_bad_speculation        (90.11%)
    158                                                          #     16.4 %  tma_frontend_bound         (79.92%)
    159                                                          #     52.0 %  tma_retiring               (90.37%)
    160 
    161        0.473990805 seconds time elapsed
    162 
    163        0.272938000 seconds user
    164        0.021266000 seconds sys
    165 </code></pre>
    166 <pre><code>perf stat foreseen lf.txt
    167 
    168  Performance counter stats for &#39;foreseen lf.txt&#39;:
    169 
    170                  0      context-switches:u               #      0.0 cs/sec  cs_per_second
    171                  0      cpu-migrations:u                 #      0.0 migrations/sec  migrations_per_second
    172              8,936      page-faults:u                    # 104842.2 faults/sec  page_faults_per_second
    173              85.23 msec task-clock:u                     #      nan CPUs  CPUs_utilized
    174            209,148      branch-misses:u                  #      0.1 %  branch_miss_rate           (88.30%)
    175        176,970,330      branches:u                       #   2076.3 M/sec  branch_frequency       (88.29%)
    176        248,919,966      cpu-cycles:u                     #      2.9 GHz  cycles_frequency         (88.29%)
    177        736,194,375      instructions:u                   #      3.0 instructions  insn_per_cycle  (88.99%)
    178          TopdownL1                                       #      3.9 %  tma_backend_bound
    179                                                          #     29.7 %  tma_bad_speculation        (89.50%)
    180                                                          #     21.2 %  tma_frontend_bound         (77.84%)
    181                                                          #     45.2 %  tma_retiring               (88.33%)
    182 
    183        0.354029324 seconds time elapsed
    184 
    185        0.066861000 seconds user
    186        0.021186000 seconds sys</code></pre>
    187 <p>This is very unscientific, especially given I was watching to see when to kill the programs, but this is how I normally start profiling. We can’t conclude anything from these results as the timings are within margin of error.</p>
    188 <p>Since Amfora can highlight code let’s see how that impacts performance. I pasted the Python code above at the top of the text file, encapsulated by gemtext preformatted text lines, and then renamed the file to <code>lf.gmi</code>. We then find:</p>
    189 <pre><code>perf stat amfora lf.gmi
    190 
    191  Performance counter stats for &#39;amfora lf.gmi&#39;:
    192 
    193                  0      context-switches:u               #      0.0 cs/sec  cs_per_second
    194                  0      cpu-migrations:u                 #      0.0 migrations/sec  migrations_per_second
    195            900,174      page-faults:u                    #  12090.4 faults/sec  page_faults_per_second
    196          74,453.35 msec task-clock:u                     #      nan CPUs  CPUs_utilized
    197        229,042,926      branch-misses:u                  #      0.4 %  branch_miss_rate           (88.94%)
    198     62,713,218,442      branches:u                       #    842.3 M/sec  branch_frequency       (88.85%)
    199    153,193,058,619      cpu-cycles:u                     #      2.1 GHz  cycles_frequency         (88.97%)
    200    306,159,421,078      instructions:u                   #      2.0 instructions  insn_per_cycle  (88.90%)
    201          TopdownL1                                       #      0.6 %  tma_backend_bound
    202                                                          #     97.8 %  tma_bad_speculation        (88.83%)
    203                                                          #     -0.1 %  tma_frontend_bound         (77.86%)
    204                                                          #      1.7 %  tma_retiring               (88.91%)
    205 
    206       28.983517177 seconds time elapsed
    207 
    208       63.894262000 seconds user
    209        8.207151000 seconds sys</code></pre>
    210 <pre><code>perf stat foreseen lf.gmi
    211 
    212  Performance counter stats for &#39;foreseen lf.gmi&#39;:
    213 
    214                  0      context-switches:u               #      0.0 cs/sec  cs_per_second
    215                  0      cpu-migrations:u                 #      0.0 migrations/sec  migrations_per_second
    216              6,551      page-faults:u                    #  90396.7 faults/sec  page_faults_per_second
    217              72.47 msec task-clock:u                     #      nan CPUs  CPUs_utilized
    218            154,134      branch-misses:u                  #      0.1 %  branch_miss_rate           (88.98%)
    219        166,258,529      branches:u                       #   2294.2 M/sec  branch_frequency       (88.99%)
    220        232,523,911      cpu-cycles:u                     #      3.2 GHz  cycles_frequency         (88.96%)
    221        705,288,446      instructions:u                   #      3.0 instructions  insn_per_cycle  (88.93%)
    222          TopdownL1                                       #      7.6 %  tma_backend_bound
    223                                                          #     23.2 %  tma_bad_speculation        (88.96%)
    224                                                          #     18.8 %  tma_frontend_bound         (77.41%)
    225                                                          #     50.4 %  tma_retiring               (88.45%)
    226 
    227        0.381682961 seconds time elapsed
    228 
    229        0.058132000 seconds user
    230        0.015949000 seconds sys</code></pre>
    231 <p>That’s a lot slower for Amfora, ~76x slower than Foreseen, and ~61x slower than it was with the normal text file. Let’s look at a flamegraph for this.</p>
    232 <object data="/images/amfora-before.svg" type="image/svg+xml" width="100%">
    233 </object>
    234 <p>So 68.34% of samples occurred while executing the GC. That’s a bit surprising as there shouldn’t be that many allocations occuring. We also see 25.47% of the samples occur when executing the RenderGemini function. Of this, most of it is spent on concatstring3, a function used to concatenate strings.</p>
    235 <p>Looking in the RenderGemini function for string concatenations we find:</p>
    236 <pre><code>rendered += fmt.Sprintf(&quot;[%s]&quot;, config.GetColorString(&quot;preformatted_text&quot;)) +
    237     buf + fmt.Sprintf(&quot;[%s:%s:-]\r\n&quot;, config.GetColorString(&quot;regular_text&quot;), config.GetColorString(&quot;bg&quot;))
    238 
    239 ...
    240 
    241 rendered += buf + &quot;\r\n&quot;
    242 
    243 ...
    244 
    245 rendered += ren
    246 
    247 ...
    248 
    249 buf += strings.TrimSuffix(lines[i], &quot;\r&quot;) + &quot;\r\n&quot;</code></pre>
    250 <p>Yeah, this isn’t great. Each of these seemingly innocuous appends is very costly. Go strings are immutable so each append creates an entirely new string, and since we accumulate into <code>buf</code> until reaching a preformatted text switch line (“```” lines), we have to re-create the accumulator string 200,000 times to parse our file.</p>
    251 <p>Fortunately, this is easy to solve by using a strings.Builder which doesn’t have this issue, and that’s <a href="https://github.com/makew0rld/amfora/pull/370/changes">what I did</a>. After this change, we can perform our profiling again to find:</p>
    252 <pre><code>perf stat amfora lf.gmi
    253 
    254  Performance counter stats for &#39;amfora lf.gmi&#39;:
    255 
    256                  0      context-switches:u               #      0.0 cs/sec  cs_per_second
    257                  0      cpu-migrations:u                 #      0.0 migrations/sec  migrations_per_second
    258              6,039      page-faults:u                    #   4871.9 faults/sec  page_faults_per_second
    259           1,239.55 msec task-clock:u                     #      nan CPUs  CPUs_utilized
    260          3,631,996      branch-misses:u                  #      0.1 %  branch_miss_rate           (89.02%)
    261      3,017,891,055      branches:u                       #   2434.7 M/sec  branch_frequency       (88.96%)
    262      4,654,531,574      cpu-cycles:u                     #      3.8 GHz  cycles_frequency         (88.93%)
    263     14,168,541,807      instructions:u                   #      3.1 instructions  insn_per_cycle  (88.81%)
    264          TopdownL1                                       #      2.2 %  tma_backend_bound
    265                                                          #     36.9 %  tma_bad_speculation        (88.80%)
    266                                                          #     18.5 %  tma_frontend_bound         (77.83%)
    267                                                          #     42.5 %  tma_retiring               (88.90%)
    268 
    269        1.185772969 seconds time elapsed
    270 
    271        1.193871000 seconds user
    272        0.039062000 seconds sys</code></pre>
    273 <p>This is much better. We are now using ~33x less cycles, and it’s ~25x faster than before. It’s also only 3x slower than foreseen on this task.</p>
    274 <object data="/images/amfora-after.svg" type="image/svg+xml" width="100%">
    275 </object>
    276 <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.</p>
    277 <p>We could continue identifying hotspots, but now there are 4 ~equally costly groupings, and as performance becomes more diffuse, optimizations will generally have a smaller impact on overall performance, so I’m going to leave this as is.</p>
    278 <h2 id="whats-next">What’s Next</h2>
    279 <p>This post only discussed on-CPU profiling for program execution. There are a few additional metrics worth profiling that I’ll discuss in the future:</p>
    280 <ol type="1">
    281 <li>Off-CPU profiling</li>
    282 <li>Memory profiling</li>
    283 <li>Build time profiling</li>
    284 </ol>]]></description>
    285 <pubDate>Sat, 17 Oct 2026 00:00:00 -0500</pubDate>
    286 <guid>gemini://blog.laack.co/basic-software-profiling-cpu-usage.gmi</guid>
    287 </item>
    288 <item>
    289 <title><![CDATA[PyGame vs. Raylib]]></title>
    290 <link>gemini://blog.laack.co/pygame-vs-raylib.gmi</link>
    291 <description><![CDATA[<p>I implemented <a href="https://cp-algorithms.com/graph/mst_prim.gmi">Prim’s algorithm</a> to create a MST of a graph in Python. I also created a visualization of it, shown below.</p>
    292 <p><video src="videos/prim.mkv" controls=""><a href="videos/prim.mkv">Video</a></video></p>
    293 <p>(This graph has 250 vertices and 1,000 edges. The source code used to generate this visualization can be found <a href="https://git.laack.co/blog/file/python/pygame-vs-raylib/prim.py.gmi">here</a>)</p>
    294 <p>Prim’s algorithm is worth understanding (albeit out of scope), and the problem it solves is finding the set of edges that minimizes the sum of their weights while guaranteeing there is exactly one path between any two vertices in the connected, weighted, undirected graph. In the case of my implementation, the weight of each edge was its length.</p>
    295 <p>As it relates to the animation, the following two things should be apparent:</p>
    296 <ol type="1">
    297 <li>The first frame must draw every edge and vertex of the graph in a greyed-out color.</li>
    298 <li>Each subsequent frame only has to draw one additional edge, the newly traversed edge, and one additional vertex, the vertex we are visiting.</li>
    299 </ol>
    300 <p>While we could render each frame from scratch based on the graph’s state, any reasonable rendering program has the ability to additively draw geometries to avoid this re-computation, and I care a bit about performance (even though this is written in Python*). Since PyGame and Raylib both support this, I’ll be using additive rendering in both of my implementations.</p>
    301 <p>* I did rewrite the animation in C++ using Raylib so I could make it <a href="https://git.laack.co/abg/">my X11 wallpaper</a>, but that’s for another blog post.</p>
    302 <h2 id="raylib">Raylib</h2>
    303 <h3 id="implementation">Implementation</h3>
    304 <p>Raylib has 2D rendered textures that can persist across frames. Here’s some Python code that makes use of them to visualize Prim’s algorithm:</p>
    305 <pre class="python"><code>import pyray as pr
    306 
    307 # ... (other imports, Vertex class definition, Edge class definition)
    308 
    309 pr.init_window(screen_width, screen_height, &quot;prim&quot;)
    310 
    311 # ... (other initialization)
    312 
    313 texture = pr.load_render_texture(screen_width,screen_height)
    314 
    315 while !done:
    316     if first:
    317         start = time.monotonic_ns()
    318 
    319         # After calling begin_texture_mode(texture) all writes will be 
    320         # sent to the texture without having to specify we&#39;re writing to the 
    321         # texture. This is also how begin_drawing() works, but for frames.
    322 
    323         pr.begin_texture_mode(texture)
    324         pr.clear_background(pr.BLACK)
    325 
    326         for edge in edge_list:
    327             edge.draw_edge(pr.DARKGRAY)
    328         for vertex in graph:
    329             vertex.draw_vertex(pr.DARKGRAY)
    330 
    331         pr.end_texture_mode()
    332 
    333         source_rec = pr.Rectangle(0, 0, screen_width, screen_height)
    334         dest_rec = pr.Rectangle(0, 0, screen_width, screen_height)
    335 
    336         pr.begin_drawing()
    337         pr.draw_texture_pro(texture.texture, source_rec, dest_rec, pr.Vector2(0, 0), 0, pr.WHITE)
    338         pr.end_drawing()
    339 
    340         first = False
    341 
    342         end = time.monotonic_ns()
    343         first_times.append(end - start)
    344 
    345         continue
    346 
    347     # ... (perform one step of Prim&#39;s algorithm)
    348 
    349     if len(to_draw_edge) != 0 or len(to_draw_vert) != 0:
    350         start = time.monotonic_ns()
    351 
    352         pr.begin_texture_mode(texture)
    353 
    354         for edge in to_draw_edge:
    355             edge.draw_edge(pr.WHITE)
    356         for vert in to_draw_vert:
    357             vert.draw_vertex(pr.WHITE)
    358 
    359         pr.end_texture_mode()
    360 
    361         source_rec = pr.Rectangle(0, 0, screen_width, screen_height)
    362         dest_rec = pr.Rectangle(0, 0, screen_width, screen_height)
    363 
    364         pr.begin_drawing()
    365         pr.draw_texture_pro(texture.texture, source_rec, dest_rec, pr.Vector2(0, 0), 0, pr.WHITE)
    366         pr.end_drawing()
    367 
    368         end = time.monotonic_ns()
    369         redraw_times.append(end - start)
    370 
    371         to_draw_vert = []
    372         to_draw_edge = []</code></pre>
    373 <p>Before our main iteration loop we initialize our texture. Then on our first iteration of the loop we draw each of the edges and vertices in our graph. On each subsequent iteration we only draw vertices added to <code>to_draw_vert</code> and edges added to <code>to_draw_edge</code>. Both lists are populated with edges and vertices that were visited since the last frame was rendered.</p>
    374 <p>This code is also instrumented to track the amount of time the first frame takes to render, and the amount of time each subsequent frame takes to render as well.</p>
    375 <p>Not included above are our Vertex and Edge classes which both implement draw functions. These functions have the following lines to draw geometries with Raylib:</p>
    376 <pre class="python"><code>pr.draw_circle(int(self.x),int(self.y), RADIUS, c) # vertex
    377 pr.draw_line(int(self.v1.x), int(self.v1.y), int(self.v2.x), int(self.v2.y), c) # edge</code></pre>
    378 <p>Per the code comment in the larger code snippet, Raylib uses global state to track which canvas is being drawn to, so these functions can be called in texture mode or drawing mode with a similar effect.</p>
    379 <h2 id="pygame">PyGame</h2>
    380 <h3 id="implementation-1">Implementation</h3>
    381 <p>PyGame persists frame state across frames by default so we don’t have to mess with rendered textures like we did with Raylib! Here’s a some code that does the PyGame rendering:</p>
    382 <pre class="python"><code>
    383 # ... (imports and such)
    384 
    385 pygame.init()
    386 display = pygame.display.set_mode((screen_width,screen_height))
    387 
    388 # ... (other initialization)
    389 
    390 while !done:
    391     if first:
    392         start = time.monotonic_ns()
    393 
    394         display.fill(BLACK)
    395 
    396         for edge in edge_list:
    397             edge.draw_edge(display, LIGHT_GREY)
    398         for vertex in graph:
    399             vertex.draw_vertex(display, LIGHT_GREY)
    400 
    401         pygame.display.update()
    402 
    403         end = time.monotonic_ns()
    404         first_time.append(end - start)
    405 
    406         first = False
    407         continue
    408 
    409     # ... (perform one step of Prim&#39;s algorithm)
    410 
    411     start = time.monotonic_ns()
    412 
    413     for edge in to_draw_edge:
    414         edge.draw_edge(display, white)
    415     for vert in to_draw_vert:
    416         vert.draw_vertex(display, white)
    417 
    418     pygame.display.update()
    419     end = time.monotonic_ns()
    420 
    421     to_draw_vert = []
    422     to_draw_edge = []</code></pre>
    423 <p>I find this code to be more readable than the Raylib code because we don’t have to maintain a standalone texture, and I also like how writing to a display is more explicit in PyGame:</p>
    424 <pre class="python"><code>pygame.draw.circle(display, WHITE, (self.x,self.y), RADIUS)
    425 pygame.draw.line(display, WHITE, (self.v1.x,self.v1.y), (self.v2.x,self.v2.y), LINE_WIDTH)</code></pre>
    426 <p>(notice the first parameter is the surface to write to)</p>
    427 <p>Despite this, the final <code>pygame.display.update()</code> is still using global state, which feels a bit strange given we have to specify which surface we are drawing to.</p>
    428 <h2 id="benchmarking">Benchmarking</h2>
    429 <p>The benchmarks were executed under the following conditions:</p>
    430 <ul>
    431 <li>Vertex count: 2,500</li>
    432 <li>Edge count: 25,000</li>
    433 <li>Screen dimensions: 5120x1440</li>
    434 <li>CPU: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz (4 cores, 8 threads)</li>
    435 <li>iGPU: Intel Corporation TigerLake-LP GT2 [Iris Xe Graphics]</li>
    436 <li>OS: Arch Linux</li>
    437 </ul>
    438 <p>Additionally, the metrics are all <strong>averages</strong> across 10 full runs.</p>
    439 <table>
    440 <thead>
    441 <tr>
    442 <th>Library</th>
    443 <th>First frame time (ms)</th>
    444 <th>Incremental frame time (ms)</th>
    445 </tr>
    446 </thead>
    447 <tbody>
    448 <tr>
    449 <td>Raylib</td>
    450 <td>29.87 ± 0.74</td>
    451 <td>2.88 ± 1.11</td>
    452 </tr>
    453 <tr>
    454 <td>PyGame</td>
    455 <td>323.39 ± 44.60</td>
    456 <td>5.59 ± 0.65</td>
    457 </tr>
    458 </tbody>
    459 </table>
    460 <p>In this benchmark Raylib’s average incremental frame render time was ~2x faster than PyGame’s, and its first frame render time was ~11x faster.</p>
    461 <h3 id="why-is-pygame-so-slow">Why Is PyGame So Slow?</h3>
    462 <p>Let’s instrument our code to dig deeper:</p>
    463 <pre class="python"><code>if first:
    464     start = time.monotonic_ns()
    465     display.fill(BLACK)
    466 
    467     edge_times = [] # new
    468     vertex_times = [] # new
    469 
    470     for edge in edge_list:
    471         se = time.monotonic_ns() # new
    472         edge.draw_edge(display, LIGHT_GREY)
    473         ee = time.monotonic_ns() # new
    474         edge_times.append(ee - se) # new
    475 
    476     for vertex in graph:
    477         sv = time.monotonic_ns() # new
    478         vertex.draw_vertex(display, LIGHT_GREY)
    479         ev = time.monotonic_ns() # new
    480         vertex_times.append(ev - sv) # new
    481 
    482     pygame.display.update()
    483     end = time.monotonic_ns()
    484     first_time.append(end - start)
    485 
    486     first = False
    487 
    488     print(&quot;Edge time avg: &quot; + str(sum(edge_times) / len(edge_times))) # new 
    489     print(&quot;Vertex time avg: &quot; + str(sum(vertex_times) / len(vertex_times))) # new
    490 
    491     continue</code></pre>
    492 <p>(Notice the addition of timing for individual edge and vertex draw times for the first frame)</p>
    493 <p>Let’s also update our Raylib code to do the same:</p>
    494 <pre class="python"><code>if first:
    495     start = time.monotonic_ns()
    496     pr.begin_texture_mode(texture)
    497     pr.clear_background(pr.BLACK)
    498 
    499     edge_times = [] # new
    500     vertex_times = [] # new
    501 
    502     for edge in edge_list:
    503         es = time.monotonic_ns() # new
    504         edge.draw_edge(pr.DARKGRAY)
    505         ee = time.monotonic_ns() # new
    506         edge_times.append(ee - es) # new
    507     for vertex in graph:
    508         vs = time.monotonic_ns() # new
    509         vertex.draw_vertex(pr.DARKGRAY)
    510         ve = time.monotonic_ns() # new
    511         vertex_times.append(ve - vs) # new
    512 
    513     pr.end_texture_mode()
    514 
    515     source_rec = pr.Rectangle(0, 0, screen_width, screen_height)
    516     dest_rec = pr.Rectangle(0, 0, screen_width, screen_height)
    517 
    518     pr.begin_drawing()
    519     pr.draw_texture_pro(texture.texture, source_rec, dest_rec, pr.Vector2(0, 0), 0, pr.WHITE)
    520     pr.end_drawing()
    521 
    522     end = time.monotonic_ns()
    523     first_time.append(end - start)
    524 
    525     first = False
    526 
    527     print(&quot;Edge time avg: &quot; + str(sum(edge_times) / len(edge_times))) # new
    528     print(&quot;Vertex time avg: &quot; + str(sum(vertex_times) / len(vertex_times))) # new
    529 
    530     continue</code></pre>
    531 <p>Running this updated code once we find:</p>
    532 <table>
    533 <thead>
    534 <tr>
    535 <th>Library</th>
    536 <th>Avg. Edge Draw Time (ns)</th>
    537 <th>Avg. Vertex Draw Time (ns)</th>
    538 </tr>
    539 </thead>
    540 <tbody>
    541 <tr>
    542 <td>PyGame</td>
    543 <td>9504.15048</td>
    544 <td>686.6508</td>
    545 </tr>
    546 <tr>
    547 <td>Raylib</td>
    548 <td>944.15884</td>
    549 <td>3016.1852</td>
    550 </tr>
    551 </tbody>
    552 </table>
    553 <p>PyGame is faster at drawing vertices (circles), but slower at drawing edges (lines). Since we are drawing many more edges than we are vertices, this contributes to making PyGame slower.</p>
    554 <p>PyGame is slower at drawing lines because it uses SDL which computes lines pixel by pixel on the CPU*, while Raylib appends the line ends to a queue for batch processing, to be asynchronously processed by the GPU.</p>
    555 <p>In the case of vertices, Raylib calls <code>DrawCircleSector()</code>, and this in turn appends geometries to the GPU drawing queue, but each circle is made of many discrete geometries which are each appended to the queue, costing cycles. Contrasting this with the PyGame approach where PyGame only has to draw a few pixels onto the surface.</p>
    556 <p>* There are ways to change the rendering pipeline for PyGame to make better use of GPUs, but these approaches are either complex or experimental.</p>
    557 <h4 id="is-that-why-pygame-is-slower">Is that why PyGame is slower?</h4>
    558 <p>That’s not the fully story. Let’s consider what the numbers above mean. The first frame renders 2,500 vertices, 25,000 edges. Each subsequent frame renders 1 vertex and 1 edge. If we multiply these numbers with the values we calculated for the amount of time each draw takes, we get the following expected frame times:</p>
    559 <table>
    560 <colgroup>
    561 <col style="width: 33%" />
    562 <col style="width: 33%" />
    563 <col style="width: 33%" />
    564 </colgroup>
    565 <thead>
    566 <tr>
    567 <th>Library</th>
    568 <th>Expected First Frame Draw Time (ms)</th>
    569 <th>Expected Subsequent Frame Draw Time (ms)</th>
    570 </tr>
    571 </thead>
    572 <tbody>
    573 <tr>
    574 <td>PyGame</td>
    575 <td>239.3204</td>
    576 <td>0.0101908</td>
    577 </tr>
    578 <tr>
    579 <td>Raylib</td>
    580 <td>31.14443</td>
    581 <td>0.003960344</td>
    582 </tr>
    583 </tbody>
    584 </table>
    585 <p>Based on this, we see the first frame times are on par with what we actually saw in our benchmarking, but the subsequent frame draw times are orders of magnitude faster than what we benchmarked, and since most frames are subsequent frames, they are severely impacting performance. Let’s see if we can figure out why this disparity exists.</p>
    586 <h5 id="pygame-flamegraph">PyGame Flamegraph</h5>
    587 <p><img src="images/pygame-flamegraph.svg" style="max-width:100%; height:auto;"></p>
    588 <h5 id="raylib-flamegraph">Raylib Flamegraph</h5>
    589 <p><img src="images/rlib-flamegraph.svg" style="max-width:100%; height:auto;"></p>
    590 <p>We see most of our time is being spent in <code>EndDrawing()</code> for Raylib and <code>pygame.display.update()</code> for Pygame. After instrumenting these calls we find the following times per invocation:</p>
    591 <table>
    592 <thead>
    593 <tr>
    594 <th>Library</th>
    595 <th>Function</th>
    596 <th>Average Call Time (ms)</th>
    597 </tr>
    598 </thead>
    599 <tbody>
    600 <tr>
    601 <td>PyGame</td>
    602 <td><code>EndDrawing()</code></td>
    603 <td>5.677199</td>
    604 </tr>
    605 <tr>
    606 <td>Raylib</td>
    607 <td><code>pygame.display.update()</code></td>
    608 <td>2.680623</td>
    609 </tr>
    610 </tbody>
    611 </table>
    612 <p>Based on our original frame time benchmarks, these calls make up almost all of the time spent rendering subsequent frames.</p>
    613 <h4 id="what-are-these-functions-doing">What Are These Functions Doing?</h4>
    614 <p>In the case of Raylib, EndDrawing does a few things:</p>
    615 <ol type="1">
    616 <li>Calls <code>rlDrawRenderBatchActive()</code>
    617 <ul>
    618 <li>This clears the batched geometries queue, issuing the OpenGL calls</li>
    619 </ul></li>
    620 <li>Calls <code>SwapScreenBuffer()</code>
    621 <ul>
    622 <li>This swaps the buffer the display scans out. In effect, this ensures the frame we just drew becomes visible.</li>
    623 <li>This is done by with <code>glfwSwapBuffers()</code>, but this is beyond scope as it requires an understanding of OpenGL and double buffering.</li>
    624 <li>In the normal case (which is how our code uses it), this function returns after the instructions have been issued, not once the frame has been rendered.</li>
    625 </ul></li>
    626 <li>Optionally waits to hit the target framerate in cases where rendering is happening faster than the target</li>
    627 </ol>
    628 <p>Most of the time spent here is on the second step. This is because issuing the instructions to swap will flush the driver’s command stream, and once a few frames are in flight, this will block until the GPU retires one.</p>
    629 <p>Let’s step through the PyGame <code>update()</code> function too:</p>
    630 <ol type="1">
    631 <li>Calls <code>pg_update()</code> in <code>src_c/display.c</code>
    632 <ul>
    633 <li>This performs some basic checks to make sure a display is set</li>
    634 </ul></li>
    635 <li><code>pg_update()</code> calls <code>SDL_UpdateWindowSurfaceRects</code>
    636 <ul>
    637 <li>This copies the buffer into a buffer owned by the windowing system (X11 in my case)</li>
    638 </ul></li>
    639 </ol>
    640 <p>The main reason this is slower is PyGame copies the whole frame on the CPU for each frame while Raylib’s frame is already in VRAM and the swap doesn’t <a href="https://en.wikipedia.org/wiki/Bit_blit">blit</a>.</p>
    641 <h2 id="takeaways">Takeaways</h2>
    642 <p>Out of the box Raylib has better performance because it performs hardware accelerated rendering. In terms of ergonomics, they both have their own quirks. Raylib feels like a C library with Python bindings (because it is!), while PyGame feels inconsistent, mixing both explicit surface drawing, and global state for frame updates.</p>
    643 <p>Personally, I’m not keen on using PyGame again because I enjoy writing performant software, and the reality of Python is it can’t be performant. This doesn’t mean I won’t ever write Python code again, it’s useful for first passes at a problem, but if I want to productionize that software I’ll have to rewrite it in a sensible programming language. The nice thing about doing a first pass on a project in Raylib is you can then rewrite it in C using Raylib directly, but the same isn’t true for PyGame.</p>]]></description>
    644 <pubDate>Sun, 20 Sep 2026 00:00:00 -0500</pubDate>
    645 <guid>gemini://blog.laack.co/pygame-vs-raylib.gmi</guid>
    646 </item>
    647 <item>
    648 <title><![CDATA[Easily Hostable Protocols Over Applications]]></title>
    649 <link>gemini://blog.laack.co/easily-hostable-protocols-over-applications.gmi</link>
    650 <description><![CDATA[<p>Motivated by Joshua Blais’ blog post about using the internet like it’s 1999 [1] I wanted to discuss an application and a protocol with characteristics that make them bad from a user freedom perspective. I also want to discuss solutions.</p>
    651 <h2 id="zulip">Zulip</h2>
    652 <p>Zulip [2] is an instant messaging program that looks like a bastion of freedom. I thought it was because it is free software which ought to be the epitome of user freedom, but it is not that simple. Free software is necessary but not sufficient for appropriate user freedom.</p>
    653 <p>Try to find a third party Zulip client for GNU/Linux. You will not. This frequently happens when you use applications and not protocols. Let’s consider three alternative protocols that facilitate instant messaging:</p>
    654 <ol type="1">
    655 <li>IRC</li>
    656 <li>XMPP</li>
    657 <li>Matrix</li>
    658 </ol>
    659 <p>Look for third party clients for any of these and they will abound. These protocols were sensibly designed to give users the freedom to decide how they interact with their data and the data others show them.</p>
    660 <p>Nothing is stopping you from creating a third-party client for Zulip. The problem is applications aren’t designed with this in mind, but protocols are. The main reason applications generally have so few clients is they frequently change their interfaces in breaking ways. Quality protocols are designed from the ground up to ensure consistent interfaces, often with backwards compatibility in mind.</p>
    661 <h2 id="at-protocol">AT Protocol</h2>
    662 <p>The AT Protocol [3] is used by the social network Bluesky. This is a common way people introduce the protocol, and it should give you pause that a protocol is frequently associated with a singular company and social network.</p>
    663 <p>Choices in the design of the AT Protocol have led to it being too costly for individuals to run full-fledged servers (see [4] for details). This results in most AT Protocol users being entirely dependent on the Bluesky organization [5] (this link is worth following). Having a strong reliance on a VC backed social media company [6] is a good way to become the product when investors demand returns. This also limits freedom by having a centralized authority with the ability to censor speech [7].</p>
    664 <p>An alternative to the AT Protocol is ActivityPub. Mastodon [8] uses ActivityPub to facilitate microblogging, and the software can be hosted on cheap hardware without a reliance on a third-party. Proponents of the AT Protocol may claim the two perform different functions, and I agree, but the centralized feed functionality the AT Protocol can provide but ActivityPub can’t is something I consider to be deeply problematic from a human psychology perspective. As such, while ActivityPub can’t directly replace “your” BlueSky feed, it will give you a healthier microblogging experience. With that said, I think the case for microblogging is lacking, and individuals should consider if microblogs, both their own and those of others, are worthwhile (my answer is emphatically no).</p>
    665 <h2 id="proposition">Proposition</h2>
    666 <p>Host your own services for the dissemination of information, ensuring the services you host implement protocols designed for the type of information you are disseminating.</p>
    667 <p>I use Git (not GitHub) for software distribution, RSS, Gemini [9], and HTTP for broadcasted textual information, email for bidirectional individual or small group communication, and XMPP or IRC for larger group communication. These are the protocols built for these use cases, and they should be used as such.</p>
    668 <h2 id="citations">Citations</h2>
    669 <p>[1] - <a href="https://joshblais.com/blog/using-the-internet-like-its-1999/">https://joshblais.com/blog/using-the-internet-like-its-1999/</a></p>
    670 <p>[2] - <a href="https://zulip.com">https://zulip.com</a></p>
    671 <p>[3] - <a href="https://en.wikipedia.org/wiki/AT_Protocol">https://en.wikipedia.org/wiki/AT_Protocol</a></p>
    672 <p>[4] - <a href="https://dustycloud.org/blog/how-decentralized-is-bluesky/">https://dustycloud.org/blog/how-decentralized-is-bluesky/</a></p>
    673 <p>[5] - <a href="https://arewedecentralizedyet.online/">https://arewedecentralizedyet.online/</a></p>
    674 <p>[6] - <a href="https://bsky.social/about/blog/03-19-2026-series-b">https://bsky.social/about/blog/03-19-2026-series-b</a></p>
    675 <p>[7] - <a href="https://bsky.social/about/support/community-guidelines">https://bsky.social/about/support/community-guidelines</a></p>
    676 <p>[8] - <a href="https://joinmastodon.org/">https://joinmastodon.org/</a></p>
    677 <p>[9] - <a href="http://geminiprotocol.net/">http://geminiprotocol.net/</a></p>]]></description>
    678 <pubDate>Sat, 25 Apr 2026 00:00:00 -0500</pubDate>
    679 <guid>gemini://blog.laack.co/easily-hostable-protocols-over-applications.gmi</guid>
    680 </item>
    681 <item>
    682 <title><![CDATA[Config Files Suck]]></title>
    683 <link>gemini://blog.laack.co/config-files-suck.gmi</link>
    684 <description><![CDATA[<p>Config files suck for three main reasons.</p>
    685 <h2 id="reasons">Reasons</h2>
    686 <ol type="1">
    687 <li>They often require learning an idiosyncratic way of defining things that doesn’t generalize across programs</li>
    688 <li>They are annoying to version and track</li>
    689 <li>They limit the configurability of software</li>
    690 </ol>
    691 <h2 id="explanation">Explanation</h2>
    692 <h3 id="learning-useless-things-sucks">Learning Useless Things Sucks</h3>
    693 <p>Config files suck because learning useless things sucks. Most config files follow their own definition format. This results in ephemeral information being learned and very quickly forgotten. Often this process repeats a few times for pieces of software that require reconfiguration to meet the expectations of the user.</p>
    694 <p>The time spent understanding the DSL of the config file would likely be better spent writing code in a proper programming language. There are two primary benefits to this. First, it builds on prior experience. If you are skilled at writing C code your ability to understand and configure software that is configured in C is improved by this prior knowledge. Second, by doing this process of configuration you are learning information that is likely less ephemeral. There are only a few good programming languages and by programming in them your proficiency in using them increases.</p>
    695 <h3 id="the-disconnect-between-configuration-and-source-code-sucks">The Disconnect Between Configuration and Source Code Sucks</h3>
    696 <p>Consider my dotfiles [1]. There are three files in my dotfiles that don’t reside in the XDG_CONFIG_HOME directory. These three files are my .bashrc, my .Xresources, and my .xinitrc files. I have these in my XDG_CONFIG_HOME directory and symlink to them from their expected locations because the programs don’t respect the XDG_CONFIG_HOME directory specification. This is annoying to setup on each system I use. A simple solution to this is to not use software that doesn’t respect the spec, but when Xorg and Bash don’t respect the spec, it becomes a bit more difficult to do so.</p>
    697 <p>The bigger issue is that the disconnect between the configuration of software and source code results in multiple sources of information contributing to the configuration of a software program. This is annoying because to achieve the same program configuration across systems one must ensure two different locations are synchronized instead of one.</p>
    698 <h3 id="being-limited-in-what-you-can-change-about-programs-sucks">Being Limited in What You Can Change About Programs Sucks</h3>
    699 <p>Config files often don’t allow for large changes to be made to programs. The changes that can be made are constrained to what is deemed reasonable by the developers of the software. This is not similar to proprietary software where the developers actively hinder the freedom of users, but by having the source code and the configuration done in the same location, you can fundamentally change the operation of the program without jumping between different locations.</p>
    700 <h2 id="the-redeeming-factor">The Redeeming Factor</h2>
    701 <p>As I see it, config files are worthwhile if users are expected not to build from source. This may be the case for many open source projects, but I personally dislike using software in this way. This is a matter of opinion, but I think one of the most valuable parts free software is the freedom to change the source code as I see fit. By distributing software with config files, this sends an implicit message to users that they are expected to use the software as is, without modifying the source code.</p>
    702 <p>If you don’t see a reason to build from source, it is your right to continue using config files. If you are building a project where you want users to configure, extend, and customize their computing experience to the fullest extent, consider doing away with config files as it forces users to directly manipulate your codebase, giving them more autonomy and flexibility. This may hinder mass adoption, but is that why you build software? It’s not why I do.</p>
    703 <h2 id="citations">Citations</h2>
    704 <p>[1] - <a href="https://git.laack.co/dotfiles">https://git.laack.co/dotfiles</a></p>]]></description>
    705 <pubDate>Wed, 19 Nov 2025 00:00:00 -0600</pubDate>
    706 <guid>gemini://blog.laack.co/config-files-suck.gmi</guid>
    707 </item>
    708 <item>
    709 <title><![CDATA[You Don't Need Anything]]></title>
    710 <link>gemini://blog.laack.co/you-dont-need-anything.gmi</link>
    711 <description><![CDATA[<h2 id="context">Context</h2>
    712 <p>The words we say have an impact on how we think. A word I find problematic is the word need.</p>
    713 <h2 id="definition">Definition</h2>
    714 <p>Need: a requirement, necessary duty, or obligation [1].</p>
    715 <h2 id="my-thoughts">My Thoughts</h2>
    716 <p><strong>Do You Really <em>need</em> Anything?</strong></p>
    717 <p>I often say this when people use an unqualified need. An unqualified need is as follows:</p>
    718 <p><strong>I <em>need</em> to eat food, I’m starving!</strong></p>
    719 <p>Aside from the fact that they likely aren’t starving, they don’t <em>need</em> food. This can be thought of in a similar way as the is-ought problem [2]. If someone says they <em>need</em> something, you can ask them, “Why do you <em>need</em> it?”. In the case of food they may say, “I <em>need</em> food to survive”, and to this you may say, “Why do you <em>need</em> to survive”, and this can continue indefinitely as needs are predicated upon something. Often need has an implicit qualification as is the case of, “I <em>need</em> food” implying that it is needed to survive, but you don’t <em>need</em> to survive. I don’t want you to die, but it is not necessary for you to live. Tying this to the definition of need, there is no requirement, duty, or obligation for someone to be alive. There are no universal requirements to do things, no one has a universal duty to do things, and no one has a universal obligation to do anything. You may <em>need</em> to complete a project at work to not get fired, but you don’t <em>need</em> to complete the project, you can just get fired, you are not obligated to not be fired.</p>
    720 <p>The danger in statements like, “I <em>need</em> to eat food”, is they create a dependence upon something. By saying you <em>need</em> something you are telling yourself that without it you are incomplete. You are beholden unto this thing. This is dangerous because it leads to acts of immorality because of the perception that something must be done. I believe this is what has led to mass surveillance. People think they <em>need</em> to do what their boss tells them to do even when they know it’s wrong.</p>
    721 <p>YOU DON’T NEED ANYTHING. You want it because you perceive the consequences of not having it are worse than having it. This is not a need. This is a want. Understand the difference.</p>
    722 <p>You don’t need to live. You don’t need food. You don’t need water.</p>
    723 <h2 id="citations">Citations</h2>
    724 <p>[1] - <a href="https://www.dictionary.com/browse/need">https://www.dictionary.com/browse/need</a></p>
    725 <p>[2] - <a href="https://en.wikipedia.org/wiki/Is%E2%80%93ought_problem">https://en.wikipedia.org/wiki/Is%E2%80%93ought_problem</a></p>]]></description>
    726 <pubDate>Fri, 17 Oct 2025 00:00:00 -0500</pubDate>
    727 <guid>gemini://blog.laack.co/you-dont-need-anything.gmi</guid>
    728 </item>
    729 <item>
    730 <title><![CDATA[Stop Collecting User Data]]></title>
    731 <link>gemini://blog.laack.co/stop-collecting-user-data.gmi</link>
    732 <description><![CDATA[<h2 id="problem-statement">Problem Statement</h2>
    733 <p>Sending the data of people who use applications you built, by default, for any purpose that is not strictly required for the application to function is morally wrong.</p>
    734 <h2 id="why-does-this-matter">Why Does This Matter</h2>
    735 <p>This matters because humans are trusting. It abuses this trust by tracking unnecessary data about application usage because most humans implicitly assume this is not being done, and they often don’t understand what the consequences of this tracking can be [1][2]. Additionally, it is unreasonable to expect users to look through your source code, all of your settings, and your docs to understand what data is being collected. If data is being collected, it should be obvious based on the purpose of the application, and if it is not obvious that it must be collected for the application to work, this should be made explicitly clear to users in the most obvious way possible.</p>
    736 <h2 id="counter-arguments">Counter Arguments</h2>
    737 <p><strong>But it is necessary to track errors so we can fix bugs and improve UX</strong></p>
    738 <p>Yes, this is often the case. Does the Linux kernel collect logs? Yes! Do they upload them to a server for aggregation? No! This is how error logging should be done. Write your logs to a log file, but don’t automatically upload them to your servers. If a user has an issue that they would like addressed, they will let you know about it. If they don’t notice or don’t mind the issue, it’s their right to not report it. Some users may not want to deal with the hassle of uploading logs when things break, so they may prefer to have an option to automatically upload their logs. This is totally fine, but only if they are informed about what is being logged and it is an opt-in.</p>
    739 <p><strong>But it is necessary to track usage to understand what users want</strong></p>
    740 <p>No, it isn’t. GitHub (bleh) issues exists, Discord (ick) exists, Matrix exists, email exists, there are countless ways software projects crowd source improvements to their applications, but it should not be done using mass surveillance. I would argue it is acceptable to have an opt-in option to collect usage data, but I do wonder about the soundness of the minds of people who choose to opt-in to such surveillance.</p>
    741 <h2 id="towards-a-solution">Towards a Solution</h2>
    742 <p>Use applications that respect your privacy. If an application you are using collects your data and is not proprietary, it is quite likely there is a fork of it that strips out the data collection, see ungoogled-chromium [3] and LibreWolf [4] as examples. If one doesn’t exist, consider making one.</p>
    743 <p>If user-respecting alternatives don’t exist and the application is proprietary, consider using WireShark [5] to see what domains the application is resolving. Once you find the data collection domains, add these domains to your /etc/hosts file or self-hosted DNS server (like a Pi-hole), and have them resolve to 0.0.0.0. This doesn’t always work because the domain that is collecting data is sometimes used for to support the core functionallity of the application, but in an ideal world this should not be necessary as you shouldn’t be using proprietary software to begin with.</p>
    744 <h2 id="citations">Citations</h2>
    745 <p>[1] - <a href="https://en.wikipedia.org/wiki/Cambridge_Analytica">https://en.wikipedia.org/wiki/Cambridge_Analytica</a></p>
    746 <p>[2] - <a href="https://www.forbes.com/sites/kashmirhill/2012/02/16/how-target-figured-out-a-teen-girl-was-pregnant-before-her-father-did/">https://www.forbes.com/sites/kashmirhill/2012/02/16/how-target-figured-out-a-teen-girl-was-pregnant-before-her-father-did/</a></p>
    747 <p>[3] - <a href="https://github.com/ungoogled-software/ungoogled-chromium">https://github.com/ungoogled-software/ungoogled-chromium</a></p>
    748 <p>[4] - <a href="https://librewolf.net/">https://librewolf.net/</a></p>
    749 <p>[5] - <a href="https://www.wireshark.org/download.gmi">https://www.wireshark.org/download.gmi</a></p>]]></description>
    750 <pubDate>Sun, 12 Oct 2025 00:00:00 -0500</pubDate>
    751 <guid>gemini://blog.laack.co/stop-collecting-user-data.gmi</guid>
    752 </item>
    753 <item>
    754 <title><![CDATA[AdNauseum, Track Me Not, and Privacy Through Obscurity]]></title>
    755 <link>gemini://blog.laack.co/adnauseum-track-me-not-and-privacy-through-obscurity.gmi</link>
    756 <description><![CDATA[<h2 id="context">Context</h2>
    757 <p>AdNauseum [1] is a fork of uBlock Origin [2] that hides ads, clicks them in the background, and aggregates the clicked ads in an easy to view interface. The key difference between UBlock Origin and AdNauseum is AdNauseum both hides and clicks ads.</p>
    758 <p>Track Me Not [3] is a browser extension that mimics human search queries to obscure real queries in the noise.</p>
    759 <h2 id="usability">Usability</h2>
    760 <p>AdNauseum is as effective as uBlock Origin at hiding advertisements. For a user, there is no trade off in the usability of the web when compared with uBlock Origin. This is nice because more restrictive approaches to privacy, like GNU IceCat [4] and Tor [5], hinder modern web usage.</p>
    761 <p>Similarly, Track Me Not has almost no impact on the usability of the web. I say almost no because the traffic it generates likely increases the probability of being shown CAPTCHAs, given that the traffic it generates is likely distributionally different than normal traffic.</p>
    762 <h2 id="effectiveness-at-improving-privacy">Effectiveness at Improving Privacy</h2>
    763 <p>AdNauseum is likely worse at protecting your privacy than UBlock Origin. By clicking ads in the background, there is an inherent trail of where you have been. In some ways this trail exists the moment the ad network sells the ad you are shown, but by using a more obscure technology than UBlock Origin, you are more likely to be fingerprinted. Despite this, AdNauseum makes the modern web a better experience to use than not having an ad blocker.</p>
    764 <p>Track Me Not may also hinder privacy, depending on your privacy goals. The inherent problem is it is phoning home to search engines over time, giving them information about where you are. Search providers are also likely to fingerprint you on the basis of these strange searches. The possible saving grace is that by having so much noise in your search history, it could difficult to figure out what you are interested in. I am uncertain about the value of this though as there are likely going to be two search distributions; Track Me Not’s, and yours. This allows sophisticated search providers to ignore the synthetic requests and track your real requests while also gaining real time IP information.</p>
    765 <p>In short, I find the idea that these tools improve privacy to be dubious.</p>
    766 <h2 id="why-you-still-might-want-to-use-them">Why You Still Might Want to Use Them</h2>
    767 <p>The value of these tools is they are a form of active resistance against ads and tracking. While your privacy is likely hindered by them, you are sending a message. That message costs ad networks and search providers money. In the case of AdNauseum, clicks are expensive for advertisers because most people ignore ads, and Track Me Not imposes computational costs on search providers. Even so, by clicking on so many ads ad networks may catch on and stop charging as much per click. Similarly, search providers may block you or start giving CAPTCHAs which likely impose less computational costs on them than running a query.</p>
    768 <h2 id="my-thoughts">My Thoughts</h2>
    769 <p>You probably shouldn’t be using them. While I enjoy active resistance, this is unlikely to be the right way to do it. It may mess with their knowledge about you if they are not sophisticated, but any sophisticated search provider or ad network, which I think most of them are, will easily sus out inauthentic traffic and gain more information about you as a result.</p>
    770 <p>Instead of using these tools, I recommend doing the following to improve privacy:</p>
    771 <ul>
    772 <li>Use Tor when possible</li>
    773 <li>Avoid sites that require signing in</li>
    774 <li>Don’t use social media</li>
    775 <li>Use a privacy respecting browser</li>
    776 <li>Use UBlock Origin</li>
    777 <li>Use a Pi-hole [6] and privacy respecting DNS servers</li>
    778 <li>Minimize your usage of search engines</li>
    779 <li>Use a variety of privacy respecting search engines</li>
    780 <li>Use local AI tools (if you must use any at all)</li>
    781 <li>Use E2EE messaging when possible</li>
    782 <li>Minimize the trackability of financial transactions</li>
    783 <li>Don’t carry a phone and minimize your usage of it</li>
    784 <li>Avoid proprietary software and software that collects data</li>
    785 </ul>
    786 <p>This results in me doing the following:</p>
    787 <ul>
    788 <li>Using Tor for most of my traffic</li>
    789 <li>Avoiding sites that require signing in</li>
    790 <li>Not using social media sites</li>
    791 <li>Using LibreWolf [7] as my default non-Tor browser</li>
    792 <li>Routing all non-Tor DNS requests through a self-hosted Pi-hole with additional domain filtering</li>
    793 <li>Using DuckDuckGo and a variety of public SearX instances for search</li>
    794 <li>Running Ollama [8] models locally</li>
    795 <li>Preferring communication with PGP encrypted emails, Matrix, or Signal</li>
    796 <li>Using cash or Monero when possible for transactions</li>
    797 <li>Not carrying my phone with me and only using it when it is the only means of achieving a specific goal (ie. SMS 2FA, communication with certain individuals, etc.)</li>
    798 <li>Only using Libre software that doesn’t collect data</li>
    799 </ul>
    800 <p>Unfortunately there are sometimes exceptions to the above for the purpose of completing my work in an efficient manner, but in my personal life, I am unwilling to compromise on these things.</p>
    801 <h2 id="citations">Citations</h2>
    802 <p>[1] - <a href="https://github.com/dhowe/AdNauseam">https://github.com/dhowe/AdNauseam</a></p>
    803 <p>[2] - <a href="https://github.com/gorhill/uBlock">https://github.com/gorhill/uBlock</a></p>
    804 <p>[3] - <a href="https://github.com/vtoubiana/TrackMeNot">https://github.com/vtoubiana/TrackMeNot</a></p>
    805 <p>[4] - <a href="https://www.gnu.org/software/gnuzilla/">https://www.gnu.org/software/gnuzilla/</a></p>
    806 <p>[5] - <a href="https://www.torproject.org/about/history/">https://www.torproject.org/about/history/</a></p>
    807 <p>[6] - <a href="https://pi-hole.net/">https://pi-hole.net/</a></p>
    808 <p>[7] - <a href="https://librewolf.net/">https://librewolf.net/</a></p>
    809 <p>[8] - <a href="https://ollama.com/">https://ollama.com/</a></p>]]></description>
    810 <pubDate>Sat, 04 Oct 2025 00:00:00 -0500</pubDate>
    811 <guid>gemini://blog.laack.co/adnauseum-track-me-not-and-privacy-through-obscurity.gmi</guid>
    812 </item>
    813 <item>
    814 <title><![CDATA[The Sustainability of YouTube]]></title>
    815 <link>gemini://blog.laack.co/the-sustainability-of-youtube.gmi</link>
    816 <description><![CDATA[<h2 id="context">Context</h2>
    817 <p>I dislike using cloud services because they may discontinue my service [1] or they may do something stupid [2] that negatively impacts me. These concerns, along with concerns about privacy [3], have led me to keep information and content I care about away from cloud services. This does make me wonder, how many people would be distraught about the loss of their content if YouTube terminated their accounts? This is not the topic today, nor is it something I can easily answer, but it is something I wonder about and would like others to consider.</p>
    818 <p>Similarly, I am skeptical of “free” services. It’s incorrect to say “if something is free, you are the product” because charity does exist, but when it comes to Google, they aren’t a charity. Their current model with YouTube is to have people upload videos to their site and show ads to some users when they watch said videos. There are also paid subscriptions, but their primary monetization comes from ads. An important point is they don’t purge content on a regular basis, except in cases of ToS violations. As such, there is a (nearly) monotonically increasing function that describes the storage requirements of YouTube. This motivates my question below.</p>
    819 <h2 id="question">Question</h2>
    820 <p>When will YouTube’s storage costs exceed their revenue if they don’t start purging old content, assuming their revenue does not increase over time?</p>
    821 <h2 id="how-to-answer-this-question">How to Answer This Question</h2>
    822 <p>We need the following information to answer this question:</p>
    823 <ul>
    824 <li>What is YouTube’s annual net profit?</li>
    825 <li>How much data does YouTube store?</li>
    826 <li>How much does data storage cost?</li>
    827 </ul>
    828 <h2 id="youtubes-profit">YouTube’s Profit</h2>
    829 <p>According to Alphabet’s 2025 Q2 earnings release [4], YouTube ads made a revenue of $9.769 billion. Annualized, this is $39.076 billion, but this is only revenue, not net profit. If we assume the operating margin across Alphabet matches the operating margin of YouTube (32%), we find an approximate net profit of $12.50432 billion / year. Actual net profit could differ from this, but since we are concerned with how much data storage this could support, we don’t need to factor in how this would be taxed.</p>
    830 <h2 id="storage-needs">Storage Needs</h2>
    831 <h3 id="total-videos">Total Videos</h3>
    832 <p>YouTube states on their official blog there are over 20 million videos uploaded per day [5]. While I don’t trust YouTube very much, and they don’t have many incentives to be honest on this topic, they seem more trustworthy in this context than the slop factory sites as they are, in fact, the ones who are hosting the content. As such, I will accept this metric.</p>
    833 <h3 id="average-video-size">Average Video Size</h3>
    834 <p>I wrote a python script that uses a curated list of popular Google Trends searches over the past few decades [6] to search YouTube for recently uploaded videos. I ran this script and compiled a list of ~7.65 million YouTube videos.</p>
    835 <p>Before continuing, I will list a few limitations of this approach:</p>
    836 <ul>
    837 <li>YouTube likely imposes some amount of algorithmic filtering when sorting by ‘recently uploaded’</li>
    838 <li>The videos in question are all public (not inclusive of private/unlisted videos)</li>
    839 <li>Less popular search terms may have a different distribution of video sizes</li>
    840 </ul>
    841 <p>These are the main flaws in my methodology, but any approach will be imperfect without being able to get the data directly from YouTube.</p>
    842 <p>Of these 7.65 million videos, I sampled 615,222 of them and queried YouTube using <code>yt-dlp</code> [7] to find all video resolutions and formats YouTube will serve. It seems unlikely to me that YouTube stores each of these resolutions on their servers, but I think it is very likely that YouTube is storing the highest resolution version they are willing to serve to users.</p>
    843 <p>Based on my findings, I propose a lower bound of ~396.17 MB / video, which assumes they are only storing the highest resolution version and all other versions are generated in real time via transcoding (I am confident this isn’t the case, but it provides a nice lower bound). I also propose an upper bound of ~1.44 GB / video, which assumes they are storing every resolution and format for each video they are serving.</p>
    844 <p>All of the code used for this is available on my git server [8].</p>
    845 <h3 id="annual-storage-increase">Annual Storage Increase</h3>
    846 <p>Using my findings above about video size and YouTube’s stated video upload rate, we find:</p>
    847 <p>Lower bound:</p>
    848 <ul>
    849 <li>7.923 PB / Day</li>
    850 <li>2.89 EB / Year</li>
    851 </ul>
    852 <p>Upper bound:</p>
    853 <ul>
    854 <li>28.895 PB / Day</li>
    855 <li>10.547 EB / Year</li>
    856 </ul>
    857 <p>Note: These values may vary depending on rounding, but they should be similar to what anyone else would find.</p>
    858 <h2 id="storage-cost-by-volume">Storage Cost by Volume</h2>
    859 <p>GCP currently charges $26 / month for 1 TB of standard multi-region, US based, cloud storage [9]. If we assume the same 32% profit margin as before, this would cost ~$17.68 / TB / month or $212.16 / TB / year. I don’t know if this is high or low relative to what they actually pay. YouTube requires quick access to many of their videos, but many of their videos are likely retrieved infrequently. Additionally, it seems likely Alphabet’s cloud storage margins are higher than the average margins across the organization. Additionally, these are only US storage prices so this could vary depending on the regions this data is being hosted in. In any case, I think this is a fair estimate.</p>
    860 <h2 id="answer-to-the-question">Answer to the Question</h2>
    861 <p>Given YouTube’s approximated net profit of $12.50432 billion / year and an estimated cost of $212.16 / TB / year for cloud storage, we find their profits can support an additional ~58.94 EB of data.</p>
    862 <p>At the lower bound of 2.89 EB / year we find YouTube’s storage costs will surpass their current profits in ~20.39 years.</p>
    863 <p>If we assume our upper bound of 10.547 EB / year we find YouTube’s storage costs will surpass their current profits in ~5.59 years.</p>
    864 <h2 id="conclusion">Conclusion</h2>
    865 <p>These are very rough bounds, especially given how difficult it is to estimate the cost per TB / year for storage of this data given their retrieval needs, but we find that in ~5.59 - ~20.39 years, YouTube will be forced to start purging old content to remain profitable at their current profit rate.</p>
    866 <h2 id="citations">Citations</h2>
    867 <p>[1] - <a href="https://killedbygoogle.com/">https://killedbygoogle.com/</a></p>
    868 <p>[2] - <a href="https://arstechnica.com/gadgets/2024/05/google-cloud-accidentally-nukes-customer-account-causes-two-weeks-of-downtime/">https://arstechnica.com/gadgets/2024/05/google-cloud-accidentally-nukes-customer-account-causes-two-weeks-of-downtime/</a></p>
    869 <p>[3] - <a href="https://www.gnu.org/proprietary/proprietary-surveillance.gmi">https://www.gnu.org/proprietary/proprietary-surveillance.gmi</a></p>
    870 <p>[4] - <a href="https://www.sec.gov/Archives/edgar/data/1652044/000165204425000056/googexhibit991q22025.htm.md">https://www.sec.gov/Archives/edgar/data/1652044/000165204425000056/googexhibit991q22025.htm</a></p>
    871 <p>[5] - <a href="https://web.archive.org/web/20250911091711/https://blog.youtube/press/">https://web.archive.org/web/20250911091711/https://blog.youtube/press/</a></p>
    872 <p>[6] - <a href="https://www.kaggle.com/datasets/dhruvildave/google-trends-dataset">https://www.kaggle.com/datasets/dhruvildave/google-trends-dataset</a></p>
    873 <p>[7] - <a href="https://github.com/yt-dlp/yt-dlp">https://github.com/yt-dlp/yt-dlp</a></p>
    874 <p>[8] - <a href="http://git.laack.co/blog/log.gmi">http://git.laack.co/blog/log.gmi</a></p>
    875 <p>[9] - <a href="https://cloud.google.com/storage/pricing#multi-regions">https://cloud.google.com/storage/pricing#multi-regions</a></p>]]></description>
    876 <pubDate>Sun, 28 Sep 2025 00:00:00 -0500</pubDate>
    877 <guid>gemini://blog.laack.co/the-sustainability-of-youtube.gmi</guid>
    878 </item>
    879 </channel>
    880 </rss>