<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Swapnil Bhole</title>
    <description>The latest articles on DEV Community by Swapnil Bhole (@swapnilb).</description>
    <link>https://dev.to/swapnilb</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4236619%2F58d87609-2607-4d2c-aecc-ca74c56cb360.jpeg</url>
      <title>DEV Community: Swapnil Bhole</title>
      <link>https://dev.to/swapnilb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/swapnilb"/>
    <language>en</language>
    <item>
      <title>The Butterfly Effect: Predicting Quantum Echoes</title>
      <dc:creator>Swapnil Bhole</dc:creator>
      <pubDate>Sun, 22 Nov 2026 23:57:53 +0000</pubDate>
      <link>https://dev.to/swapnilb/the-butterfly-effect-predicting-quantum-echoes-1he6</link>
      <guid>https://dev.to/swapnilb/the-butterfly-effect-predicting-quantum-echoes-1he6</guid>
      <description>&lt;p&gt;&lt;em&gt;Seven quantum circuits on BlueQubit, three simulators, 2,440 out of 3,000 points.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A butterfly flaps its wings in Brazil, and weeks later there's a tornado in Texas. That's the butterfly effect: tiny changes that ripple into big ones.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnxyj2ie4vy715drrt3xd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnxyj2ie4vy715drrt3xd.png" alt="Quantum butterfly" width="800" height="800"&gt;&lt;/a&gt;&lt;br&gt;
Quantum computers have their own butterfly effect, and physicists measure it with something called a &lt;em&gt;quantum echo&lt;/em&gt;. I recently worked through seven of these echo problems posted by &lt;a href="https://app.bluequbit.io" rel="noopener noreferrer"&gt;BlueQubit&lt;/a&gt;, and this is the story of how it went, written for people who have never touched a qubit.&lt;/p&gt;

&lt;h2&gt;
  
  
  The story: forward, flap, rewind
&lt;/h2&gt;

&lt;p&gt;Picture a quantum circuit as a movie:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Play it forward.&lt;/strong&gt; The qubits interact and get tangled together.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flip one qubit.&lt;/strong&gt; This is the butterfly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Play it backward.&lt;/strong&gt; Rewind everything exactly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check each qubit.&lt;/strong&gt; How strongly does its echo come back?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Without the flip, rewinding would bring every qubit home perfectly. With it, some qubits come back changed and some barely notice. The task was to predict, for every qubit, a single number between −1 and +1 describing that echo. Physicists call this an out-of-time-order correlator, or OTOC. The true answers were hidden, and my score depended on how closely my pattern of numbers matched them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why you can't just simulate it
&lt;/h2&gt;

&lt;p&gt;A full state-vector representation of &lt;em&gt;n&lt;/em&gt; qubits stores 2ⁿ complex amplitudes. At 16 bytes per amplitude, every additional qubit doubles the memory required:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Qubits&lt;/th&gt;
&lt;th&gt;Memory for an exact simulation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;25&lt;/td&gt;
&lt;td&gt;0.5 GB (a laptop)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;td&gt;17 GB (one GPU)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;36&lt;/td&gt;
&lt;td&gt;1.1 TB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;38&lt;/td&gt;
&lt;td&gt;4.4 TB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The circuits went from 4 qubits to 38. At 36–38 qubits, straightforward full-state simulation exceeds the memory available on many individual machines. Approximations become attractive, but their accuracy needs to be checked.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three ways to follow a butterfly
&lt;/h2&gt;

&lt;p&gt;BlueQubit lets you run the same circuit on different simulators by changing one word in your code. I used three:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Exact&lt;/strong&gt; (&lt;code&gt;cpu&lt;/code&gt;, &lt;code&gt;gpu&lt;/code&gt;): keep every possibility. Perfect, but only for smaller circuits.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MPS&lt;/strong&gt; (&lt;code&gt;mps.cpu&lt;/code&gt;, &lt;code&gt;mps.gpu&lt;/code&gt;): keep only the strongest links between neighbouring qubits. The knob is the &lt;em&gt;bond dimension&lt;/em&gt; χ; higher is closer to the truth, and slower.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pauli path&lt;/strong&gt; (&lt;code&gt;pauli-path&lt;/code&gt;): follow only the loudest "storylines" through the circuit and drop the faint ones. The knob is a &lt;em&gt;threshold&lt;/em&gt;; lower is closer to the truth, and slower.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How the seven circuits went
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Circuit&lt;/th&gt;
&lt;th&gt;Qubits&lt;/th&gt;
&lt;th&gt;What worked&lt;/th&gt;
&lt;th&gt;Score&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;S1, S2, S3&lt;/td&gt;
&lt;td&gt;4, 16, 25&lt;/td&gt;
&lt;td&gt;Exact&lt;/td&gt;
&lt;td&gt;300 / 300&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;G1 (chain)&lt;/td&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;td&gt;Exact on GPU&lt;/td&gt;
&lt;td&gt;300 / 300&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;G2 (chain with weak links)&lt;/td&gt;
&lt;td&gt;36&lt;/td&gt;
&lt;td&gt;MPS&lt;/td&gt;
&lt;td&gt;600 / 600&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;G3 (6×6 grid)&lt;/td&gt;
&lt;td&gt;36&lt;/td&gt;
&lt;td&gt;MPS, after Pauli path failed&lt;/td&gt;
&lt;td&gt;640 / 800&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;G4 (6×6 grid + 2)&lt;/td&gt;
&lt;td&gt;38&lt;/td&gt;
&lt;td&gt;Pauli path, tightened&lt;/td&gt;
&lt;td&gt;600 / 1,000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Total&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;2,440 / 3,000&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;My favourite result was G2. The qubits sit in a chain with two weak links in it. Between those links the echo came back strong; everywhere else it was essentially zero. The weak links fenced the butterfly's effect in.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the butterfly taught me
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Check the boring stuff first.&lt;/strong&gt; Quantum software disagrees about which end of a label is qubit 0. Before spending a single credit, I wrote a tiny simulator that ran on my laptop, ran the smallest practice circuit both ways, and only moved on when BlueQubit's answers matched mine exactly. Every point after that depended on that check.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practice can mislead.&lt;/strong&gt; On the practice grid, Pauli path matched the exact answer almost perfectly, so I trusted it on the real grid (G3). It quietly returned zeros for most qubits and scored 240 out of 800. The faint storylines it threw away &lt;em&gt;were&lt;/em&gt; the answer. Switching to MPS, then rerunning the largest values at a higher bond dimension, took it to 640. A method only transfers if the practice looks like the real problem.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If it still moves, it isn't done.&lt;/strong&gt; On G2, one qubit read 0.93 at χ = 64 and 0.64 at χ = 256. On G4, tightening the Pauli-path threshold moved some values by 4–7× and lifted the score from 400 to 600. A converged answer is one that stops changing when you give it more resources.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Change one thing at a time.&lt;/strong&gt; Each circuit allowed ten tries, and only the best counted. Changing one thing per try turned the scoreboard into a lab instrument: when a single qubit's new value cost 160 points, I knew exactly what to undo. The platform's limits (one GPU job at a time, ten CPU jobs) shaped the plan too, so I kept the GPU on the hardest qubits and ran CPU jobs in parallel.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd try next
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;G4:&lt;/strong&gt; about a dozen qubits never got the tighter threshold. Earlier refinements moved some values several times over, so that's where the missing points are.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;G3:&lt;/strong&gt; a few qubits flipped sign between bond dimensions, which means they weren't converged yet. The next step is χ = 256 on the large values.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Thanks
&lt;/h2&gt;

&lt;p&gt;Thanks to the BlueQubit team and the MidWest Quantum Hackathon for a beautiful set of problems, and for a platform where exact, MPS and Pauli-path simulations, on CPU or GPU, are one word apart.&lt;/p&gt;

&lt;p&gt;If you want to try it yourself, BlueQubit's tutorials are a good place to start: &lt;a href="https://app.bluequbit.io/tutorials" rel="noopener noreferrer"&gt;app.bluequbit.io/tutorials&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://medium.com/@swapbhole22/the-butterfly-effect-predicting-quantum-echoes-7a95323c42bf" rel="noopener noreferrer"&gt;Medium&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  About the author
&lt;/h3&gt;

&lt;p&gt;I’m Swapnil Bhole, an Electrical and Computer Engineering graduate from the University of Michigan (UMich), Ann Arbor. I enjoy exploring problems across quantum computing, computer architecture, and high-performance computing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Connect:&lt;/strong&gt; &lt;a href="https://swapnilb222.github.io" rel="noopener noreferrer"&gt;Portfolio&lt;/a&gt; · &lt;a href="https://www.linkedin.com/in/swapnilbhole22" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

</description>
      <category>quantumcomputing</category>
      <category>programming</category>
      <category>computerscience</category>
      <category>qubit</category>
    </item>
    <item>
      <title>23 Minutes Before the Freeze: Shortest Paths at Hackathon Raptors: Speed Demon</title>
      <dc:creator>Swapnil Bhole</dc:creator>
      <pubDate>Tue, 10 Nov 2026 09:16:09 +0000</pubDate>
      <link>https://dev.to/swapnilb/23-minutes-before-the-freeze-shortest-paths-at-hackathon-raptors-speed-demon-2kj0</link>
      <guid>https://dev.to/swapnilb/23-minutes-before-the-freeze-shortest-paths-at-hackathon-raptors-speed-demon-2kj0</guid>
      <description>&lt;p&gt;08:38 on Monday, November 2, Ann Arbor time. I push, and a few minutes later the live board says &lt;strong&gt;0.0960 s&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Twenty-two minutes earlier, the same code had run in 0.0854 s. Code freeze is at 10:00. Whatever sits on my branch then is my entry, and the final time is the mean of the middle three of five runs, so a version that is fast only on good days is a bad version.&lt;/p&gt;

&lt;p&gt;I'll come back to 08:38. First, what the 0.0960 was measuring.&lt;/p&gt;

&lt;h2&gt;
  
  
  The task
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://speeddemon.dev" rel="noopener noreferrer"&gt;Speed Demon 2026&lt;/a&gt; is a 72-hour performance championship run by &lt;strong&gt;Hackathon Raptors&lt;/strong&gt;. Everyone gets the same task, the same data and the same scoring machine: an Intel i5-13500 with six P-cores, 12 threads, turbo off, a fixed 2.5 GHz, 8 GB of memory. Output has to match the expected answers byte for byte. The efficiency score mixes wall time, peak memory, lines of code and dependencies, and human judges decide the rest.&lt;/p&gt;

&lt;p&gt;Track D: answer 2,000 shortest-path queries on a road network with 1.74 million nodes and 5 million one-way, weighted edges. The clock starts before the input file is read. So the job is half graph building, half searching, and you pay for both.&lt;/p&gt;

&lt;p&gt;I entered solo, under the team name &lt;code&gt;sweetdreams&lt;/code&gt;. All the code and a step-by-step log with every board run ID are here: &lt;strong&gt;&lt;a href="https://github.com/swapnilb222/sweet-dreams-demon-sub" rel="noopener noreferrer"&gt;github.com/swapnilb222/sweet-dreams-demon-sub&lt;/a&gt;&lt;/strong&gt; (Track D is in &lt;code&gt;track-d/&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Here is every Track D push that reached the board. Black dots were kept. Open circles were tried on the board and thrown out. Gray squares are the same code run again.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fh5u72ig1ag2atfhafulj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fh5u72ig1ag2atfhafulj.png" alt="Every Track D push that reached the board, time and memory per step" width="800" height="651"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Figure 1. Every Track D push that reached the live board. (a) Wall time. The red stepped line is the best time so far for code I kept; it ends at the code I froze. Step 1 (447 ms) is off the scale. (b) Peak memory; steps 1 and 2 are off the scale. Shaded bands group the pushes by session.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Sunday, 03:08: &lt;code&gt;trackd step1&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;That was the commit message. I am not proud of my commit messages from Sunday morning.&lt;/p&gt;

&lt;p&gt;Step 1 was plain parallel C++: memory-map the file, parse it on 12 threads, build a compressed graph, run a bidirectional Dijkstra per query. &lt;strong&gt;447 ms, 169 MB.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It was slow for a boring reason. The node ids in the input are a random permutation of the map. Two intersections a block apart can sit megabytes apart in memory, so almost every step of a search missed the cache. The search was mostly waiting.&lt;/p&gt;
&lt;h2&gt;
  
  
  04:05: three ideas in one push
&lt;/h2&gt;

&lt;p&gt;An hour later, step 2 brought it to &lt;strong&gt;109 ms and 65 MB&lt;/strong&gt;. Three changes, all aimed at the same waiting.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqpkr33z0hr3bjyi68l7k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqpkr33z0hr3bjyi68l7k.png" alt="The four stages of the program" width="799" height="332"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Figure 2. The four stages of the final program. All four are inside the timed run.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chain contraction.&lt;/strong&gt; About 30% of the nodes in a road network just continue a road: at most two ways out, nothing to decide. If one of them isn't a query endpoint, no search ever needs to stop there. So when an edge leads into a chain of them, I follow the chain to the first node that has to stay and point the edge straight at it, with the weights summed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftceycby2t4sfc88kkz3s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftceycby2t4sfc88kkz3s.png" alt="Chain contraction: a chain of pass-through nodes becomes one edge" width="799" height="190"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Figure 3. Chain contraction. (a) Hollow nodes have at most two ways out and are not query endpoints. (b) The search never stops at them: the edge from A points straight at B, with the weights summed.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The graph drops from 1.74M nodes and 5.0M edges to 1.22M and 3.96M. Every search shrinks with it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Renumbering by breadth-first search.&lt;/strong&gt; Each thread grows compact BFS regions over the graph and hands out new ids in the order it visits nodes. Nodes that are close on the map end up close in memory. Three pushes later, in step 5, contraction moved inside this same pass, so now it costs no extra scan.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A bucket queue instead of a binary heap.&lt;/strong&gt; The weights are mostly small integers (the median is about 120), so distances can be grouped into fixed-width buckets in a ring, with a tiny heap for the rare long jump. Each query also starts with a short forward-only search, which settles nearby targets by itself. Only then does it search from both ends, always growing the side that has done less work.&lt;/p&gt;

&lt;p&gt;That push did more than all the later ones put together. The rest of this post is about the other 24 ms.&lt;/p&gt;
&lt;h2&gt;
  
  
  Sunday afternoon: three memory peaks
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Memory improv little&lt;/code&gt;, 13:25. Then &lt;code&gt;2groupthreads trackd&lt;/code&gt;, 13:49.&lt;/p&gt;

&lt;p&gt;Memory carries a fifth of the efficiency formula's weight, so I logged the program's memory over time and found three separate peaks, in three different phases. While building, the parsed edges and the new rows were alive together; the parsed edges now sit in page-sized bins that get released group by group. While searching, each bucket kept the largest size it ever reached, about 100,000 entries per direction, when only about 3,000 are live at once; buckets now borrow from shared, recycled blocks. Renumbering got one-byte degrees instead of four-byte ones.&lt;/p&gt;

&lt;p&gt;65 MB went to 55 MB. Then I learned something annoying: releasing memory while other threads are working stalls all of them, because the kernel has to flush every core's address translations. So the releases moved to the gaps between build passes.&lt;/p&gt;
&lt;h2&gt;
  
  
  The race I left in on purpose
&lt;/h2&gt;

&lt;p&gt;When a BFS region claims a node during renumbering, it uses a plain read and a plain write. Two threads can race and both claim the same node. An atomic compare-and-swap on every claim fixes that, and it cost 4 to 10 ms, which is more than most of my later steps saved.&lt;/p&gt;

&lt;p&gt;On a real road graph a double claim just makes a harmless duplicate. So I kept the race.&lt;/p&gt;

&lt;p&gt;Then a 32-node test case started failing in some runs. On a graph with nothing to contract, the duplicates could push the node count past the width of the node-id field inside an edge word. A later stress run found that the same race could also overrun a thread's edge buffer on a tiny graph.&lt;/p&gt;

&lt;p&gt;The fix keeps the cheap claims and checks afterwards. If the duplicates would overflow the id field, a thread's buffer or the raw graph, the whole pass runs again with exact atomics. On full-size inputs that never happens. On tiny graphs it does, and since then every version has gone through 1,500 to 2,500 runs of the 41 small test cases, at 1, 2, 5 and 12 threads, with and without the address sanitizer. You can decide for yourself whether that's engineering or a bet with a good alibi. I'd make it again.&lt;/p&gt;
&lt;h2&gt;
  
  
  About "the two-line change that halved it"
&lt;/h2&gt;

&lt;p&gt;The side quest asks for one. I don't have one. The biggest jump was step 2, and that was about 220 new lines. After step 2, the wins came in 4 to 9 ms pieces.&lt;/p&gt;

&lt;p&gt;The closest thing to a two-line change was step 9. In C++, a store through one &lt;code&gt;u32*&lt;/code&gt; may change any other &lt;code&gt;u32&lt;/code&gt; in memory unless the compiler can prove it doesn't. My hot loops store &lt;code&gt;u32&lt;/code&gt; values while reading &lt;code&gt;u32&lt;/code&gt; arrays. So after every store, GCC reloaded the row offsets, the row end, an edge counter, even the array pointers themselves.&lt;/p&gt;

&lt;p&gt;The real diff was 35 lines in and 26 out, across several loops, but the idea fits in two:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// the shape of the fix, simplified&lt;/span&gt;
&lt;span class="n"&gt;u32&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;__restrict&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// copy into locals, promise no aliasing&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;u32&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;row_end&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;           &lt;span class="c1"&gt;// the compiler can keep these in registers now&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Renumbering went from about 29 ms to 22 to 25 ms. On the board: 100 ms to 96 ms. Not half. About 4%.&lt;/p&gt;

&lt;p&gt;The change I'm happiest with came right after it, in step 10. The renumbering pass visits nodes in a random order, and with separate offset and edge arrays each visit cost two cache misses in a row: one to find the row, one to read it. Now every node has four fixed edge slots, which covers 97% of the nodes in this network. A node's edges are one miss away, and a prefetch can fetch them straight from the node id.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fb75pjvsbqf9lm3sczpgc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fb75pjvsbqf9lm3sczpgc.png" alt="The 32-bit edge word and the four-slot row" width="800" height="373"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Figure 4. (a) One edge is one 32-bit word. The head field is sized from the node count at run time: 21 bits for this graph. (b) The raw graph gives every node four fixed slots, so its edges are at a known address.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Every edge is a single 32-bit word: head node in the low 21 bits, weight above it. The 0.1% of weights that don't fit go to a side table. An empty slot is all ones, which no real edge can be because the id field is sized from n + 1. Step 10: &lt;strong&gt;96 ms to 89 ms.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Step 8, before both of these, was the same kind of fix: find one specific stall and remove it. "Is this new path shorter?" is close to a coin flip in a Dijkstra, so the branch predictor guessed wrong about half the time. The relaxation now always writes the smaller distance and always writes the queue entry, and only the counter moves when the path actually improved. Together with prefetching in the chain walks, that took the board from 109 ms to 100 ms.&lt;/p&gt;

&lt;h2&gt;
  
  
  The control group
&lt;/h2&gt;

&lt;p&gt;Somewhere around step 15 I noticed the board drifted. Identical code ran 87 ms in one session and 91 ms in another. That's the size of most of my improvements.&lt;/p&gt;

&lt;p&gt;My Track A entry, a log-parsing task in the same repo, never changed between Track D pushes, and the board ran it on every push. So Track A's time worked as a thermometer for the machine. When Track A came back 20% slow, I didn't believe the Track D number from that push either.&lt;/p&gt;

&lt;p&gt;That rule caught a false negative. Step 19 cut instructions in the search and the parser, landed on a busy box (Track A 24% to 38% slow), and measured 94 ms. I reverted it. Forty minutes later, at 23:03, I pushed the identical code again in a quieter period: 86 ms, my best at the time.&lt;/p&gt;

&lt;p&gt;Three ideas didn't survive the board at all. Unmapping the input file from the parsing threads, to shorten exit, made things slower, probably because each unmap interrupts every other thread. Putting the reverse graph on 2 MiB pages, on the theory that the i5-13500 only covers 8 MB with small-page translations, measured exactly the same. A barrier that spins briefly before sleeping changed nothing.&lt;/p&gt;

&lt;h2&gt;
  
  
  The profile I read wrong
&lt;/h2&gt;

&lt;p&gt;I developed on a laptop with two P-cores among its twelve, and turbo. Profiled there, the program looked memory-bound: memory stalls seemed to be the biggest cost. So I spent a chunk of Monday morning checking my sizes against the scoring machine's caches, with Valgrind's cachegrind configured for 48 KB of L1 and the i5-13500's 24 MB last level.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Foch5shqzrsnnovq2q5vg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Foch5shqzrsnnovq2q5vg.png" alt="What the cache simulator said about my size choices" width="800" height="362"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Figure 5. Estimated cycles for variants of the program, compared with the code at the time. Valgrind's cachegrind ran with the i5-13500's cache sizes. I converted its counts to cycles with a rough model: 2.5 instructions per cycle, 30 cycles for an L1 miss that hits a lower cache, 200 cycles for a miss that goes to memory.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The laptop's smaller cache exaggerated memory costs by about 6%, which was reassuring: contraction is still clearly worth it, and my big choices hadn't been tuned for the wrong cache. 64-node BFS blobs looked 2.7% better in the simulator. In 40 interleaved wall-clock runs they lost 2 to 3 ms. The simulator counts misses. It can't see how many of them the CPU overlaps.&lt;/p&gt;

&lt;p&gt;The real correction was arithmetic I should have done on Sunday night, when step 19 was already cutting instructions on a hunch. The board ran about 2.9 billion instructions in 85 ms. Spread across six cores at a fixed 2.5 GHz, that's about 2.3 instructions per cycle per core, averaged over the whole run. On the scoring machine the program was close to &lt;strong&gt;instruction-bound&lt;/strong&gt;. My laptop turbos to almost twice that clock, which makes instructions cheap and memory look expensive. There had been a hint earlier, too: deeper prefetching in the search never helped, at any distance.&lt;/p&gt;

&lt;p&gt;I'll come back to what that changed. First, 08:38.&lt;/p&gt;

&lt;h2&gt;
  
  
  Back to 08:38: the 16-bit labels
&lt;/h2&gt;

&lt;p&gt;A search spends much of its time reading and writing distance labels, so their size decides how many cache lines it touches. Almost every answer in this task is small: median about 1,200, 99th percentile about 8,500. So at 08:12 I pushed searches with 16-bit labels, a quarter the size of 64-bit ones. A label saturates at 65,535, and anything below that is a real path length, so a result under it is exact. Queries that hit the ceiling, or have no path, get answered again with 64-bit labels. That was 16 of the 2,000, about 1.5% of query time. Locally, the query phase went from 22.9 ms to 21.0 ms.&lt;/p&gt;

&lt;p&gt;The board gave it 85.5 and 94.9 ms on a busy box, then 85.4 ms on another busy box. Two ties with my best. And then 96.0 ms for the 08:38 push, on a quiet box, with Track A at its normal time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9tqkzab1sy5312jln0x9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9tqkzab1sy5312jln0x9.png" alt="Fastest single run vs. the run that decides the score" width="800" height="449"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Figure 6. Board runs for each version tried on Monday morning. Open circles: the box was busy, because my unchanged Track A ran slower than usual in the same push. Filled dots: Track A ran at its usual time. The red dot is the quiet-box run that made me revert. The shaded band is every run of the step 23 program before I reverted to it. The dashed line is the final 84.9 ms.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Four runs: two great, two bad. Up to then, the step 23 code it was replacing had never run outside 85.5 to 87.4 ms. With the mean of the middle three of five runs deciding the score, the 16-bit version was the riskier bet, whatever its best run said. My own first wall-clock comparison had also shown it slightly behind overall, even with the faster query phase, and I never found out why.&lt;/p&gt;

&lt;p&gt;08:43: &lt;code&gt;back to step 23's code, minus 8 header lines already included&lt;/code&gt;. The header cleanup stayed because it changes nothing in the binary and still saves lines.&lt;/p&gt;

&lt;h2&gt;
  
  
  09:21: fewer instructions for a fixed clock
&lt;/h2&gt;

&lt;p&gt;If the machine is instruction-bound, count instructions. Valgrind's per-line counts said the search's inner loop spent about 50 instructions per edge relaxation (18.7 million relaxations), and the parser about 108 per input line. Three changes, all with the same answers and the same memory accesses:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A fast path for light edges.&lt;/strong&gt; An edge lighter than the bucket ring's reach can't land outside the ring when it's relaxed from the bucket being settled. That's every edge except the 0.1% with escaped weights. So the range check only runs for heavy edges, out of line.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A sentinel bucket tail.&lt;/strong&gt; Every empty bucket points at one permanently full block. A single "is the tail block full?" test now covers both the full case and the empty case.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Digits converted with SSE.&lt;/strong&gt; Three multiply-shift-mask steps per number became two instructions, &lt;code&gt;pmaddubsw&lt;/code&gt; and &lt;code&gt;pmaddwd&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxq03320r1prp0q5r6w9g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxq03320r1prp0q5r6w9g.png" alt="Step 28: 7.8% fewer instructions" width="800" height="366"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Figure 7. (a) Instructions per full run, counted exactly with Valgrind. Simulated cache misses did not change. (b) The arithmetic that says the scoring machine was close to instruction-bound.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;On the laptop it was even. On the board, with Track A at its normal time: &lt;strong&gt;84.9 ms, 56.6 MB.&lt;/strong&gt; My best run of the event.&lt;/p&gt;

&lt;h2&gt;
  
  
  09:33
&lt;/h2&gt;

&lt;p&gt;I had 27 minutes left and one more idea: 32-bit labels, which kept the instruction count the same and cut simulated L1 misses by 10%. I pushed it as a board test. It came back at 94.5 ms on a box where Track A was 23% slow. Across every narrow-label version I'd tried, three of five board runs had been slow.&lt;/p&gt;

&lt;p&gt;09:37: &lt;code&gt;back to step 28's code for the freeze&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The freeze landed at 10:00 with step 28 on the branch, and Track D was &lt;strong&gt;3rd on the live leaderboard&lt;/strong&gt;. The final scores, measured on a holdout dataset nobody has seen, come out on November 13.&lt;/p&gt;

&lt;p&gt;The 16-bit labels are still in the history, commit &lt;code&gt;ca05322&lt;/code&gt;. I still don't know why the quiet box hated them.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Speed Demon 2026 was run by Hackathon Raptors. Full code, the Track D performance log with every board run ID, and the other three tracks: &lt;a href="https://github.com/swapnilb222/sweet-dreams-demon-sub" rel="noopener noreferrer"&gt;github.com/swapnilb222/sweet-dreams-demon-sub&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;More about me: &lt;a href="https://swapnilb222.github.io/" rel="noopener noreferrer"&gt;swapnilb222.github.io&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Connect with me on LinkedIn: &lt;a href="https://www.linkedin.com/in/swapnilbhole22/" rel="noopener noreferrer"&gt;linkedin.com/in/swapnilbhole22&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>performance</category>
      <category>cpp</category>
      <category>algorithms</category>
      <category>optimization</category>
    </item>
  </channel>
</rss>
