<- all posts
Directive 2026-05-27

Programming Against the Laws of Physics

Every `for` loop is a physical event. Code compiles down to charge moved across gates, charge dissipates as heat, and heat has to go somewhere before the chip throttles or the battery drains. The mental model of "code as text" stops the story at step one.

By AP39 / / 6 min read

You think you're writing code. You're actually deciding how many electrons move through a few billion transistors, how fast they move, and how much heat that motion has to shed before the silicon underneath your thumb gets uncomfortably warm. Every for loop is a physical event. Every allocation is a small, real transaction in a system governed by thermodynamics, not syntax. The compiler doesn't turn your logic into something metaphorically electrical. It turns it into something literally electrical, and the laws that govern that translation don't care how elegant your abstraction layer looked in the pull request.

The Rack Doesn't Care About Your Architecture Diagram

Spec out a server, and at some point the conversation stops being about cores and RAM and becomes a conversation about a number most engineers never think about twice: the TDP, the thermal design power, the wattage a chip is expected to dissipate as heat under sustained load. A Ryzen 7 pulling somewhere around 65-105W isn't an abstract spec sheet line. It's a commitment that something, somewhere, a heatsink, a fan curve, a cooling budget in a data center's power envelope, has to physically carry that energy away as heat, continuously, for as long as the box stays racked.

This is the part that never makes it into the system design interview. You draw boxes and arrows for your microservices. You never draw the cooling. But the cooling was always part of the design, whether you drew it or not, because every CPU cycle your service consumes has to go somewhere as heat before it can go anywhere as an HTTP response.

Scale that thought up to a data center and the physical reality becomes the entire economics of the industry. Cooling isn't a line item next to compute, it's frequently comparable to the compute cost itself, because you're not just paying to run the silicon, you're paying to run an entire second system whose only job is removing the byproduct of running the first one. Every inefficient query, every needlessly polled background job, every service that wakes up every thirty seconds "just to check," is a tiny recurring tax on that cooling budget, multiplied by however many machines are running your code.

Your Phone Is a Much Smaller, Much Angrier Data Center

Shrink that same physics problem down to something that fits in a pocket and it gets worse, not better, because a phone has none of a server rack's luxuries. No dedicated cooling budget. No fan. No rack-scale airflow engineering. Just a thin slab of aluminum and glass, a battery smaller than a deck of cards, and a chip that has to make thermal decisions in real time because there is nowhere for the heat to go except into your hand.

This is why mobile SoCs throttle. Sustained load past a certain thermal threshold, and the chip will voluntarily downclock itself, trading performance for survival, because the alternative is damaging silicon that has nowhere to dump excess heat. That stutter you feel twenty minutes into a demanding session isn't a software bug. It's the chip making a physics-based decision that your code didn't get a vote in, because your code created a thermal situation the silicon had to unilaterally resolve.

And here's the detail most engineers never internalize: a background process that wakes the CPU from a deep sleep state every few seconds isn't a minor inefficiency you can round off. Waking a modern chip from idle costs a disproportionate energy penalty compared to staying in that low-power state, because bringing cores and caches back online has real physical overhead independent of the work actually being done once awake. A polling loop that checks a network condition every ten seconds "just to be safe" isn't ten seconds of idle waiting punctuated by cheap checks. It's the CPU being yanked out of a low-power state, spinning up, doing a trivial amount of work, and going back down, over and over, paying the wake-up tax every single time. Do that a few thousand times over a day and you have measurably shortened someone's battery life for a feature that, on paper, does almost nothing.

That's the energy vampire. Not the heavy computation, people generally notice and budget for heavy computation. It's the quiet, "harmless," constantly-repeating background task that never shows up as a spike on any profiler's headline number, because no single instance of it is expensive. The cost isn't in any one wake-up. It's in the multiplication.

Code as Text vs. Code as Voltage

The mental model most engineers carry around is "code as text." You write a function, it expresses an intent, the intent gets fulfilled, done. That model is fine for correctness. It is actively misleading for performance and power, because it hides the actual chain of custody between what you typed and what physically happened.

The real chain looks more like this: your function compiles down to instructions, instructions get fetched and decoded, decoding and execution require transistors to switch state, switching state requires moving charge across a gate, moving charge dissipates energy as heat, and heat has to go somewhere before the chip either throttles or the battery drains. "Code as text" stops the story at step one. "Code as physical reality" follows it all the way to a fan spinning up, or a phone getting warm in a pocket, or a five-percent battery drop over an hour that a user will feel and never be able to explain.

Once you actually hold that whole chain in your head, certain decisions stop looking like style preferences and start looking like physical negotiations. An unnecessary re-render isn't just wasted CPU cycles in the abstract, it's a small quantity of real charge moved for no reason, dissipated as heat for no reason, on a device with a fixed and shrinking energy budget. A background sync interval set to "every few seconds, just to feel responsive" is a recurring wake-up tax levied against someone's battery, paid whether or not the sync ever finds anything worth syncing.

Sustainable Engineering Isn't a Slogan, It's a Watt

"Sustainable engineering" gets used as marketing language often enough that it's easy to dismiss as a slogan. But at the level of a single running app, sustainability has an extremely literal, extremely unglamorous definition: how many joules did this feature cost, and did the user get value equal to that cost. A poorly-written polling loop that drains three percent of someone's battery over a commute isn't an aesthetic failure. It's measurable energy, generated somewhere on a grid, converted to heat inside someone's pocket, for a feature that could have achieved the identical user-facing result with a fraction of the wake-ups.

This is the actual argument for writing tight, deliberate, physically-aware code, and it has nothing to do with nostalgia for a leaner era of software. It's the recognition that every abstraction you stack on top of the hardware is still, underneath all of it, a request for electrons to move a certain way, generate a certain amount of heat, and drain a certain amount of stored energy. You can write code as if none of that is true. The silicon will disagree with you anyway, quietly, at 2am, in the form of a background GC pause, a thermal throttle, or a battery that's mysteriously dead by 3pm.

Write the loop like it's going to run a hundred times a second on a chip the size of a fingernail with nowhere to put the heat, because it is. Programming was never abstract. It was always physics, wearing a very convincing disguise.