🌐 US-Proxy
>
Peter Alexander

Posted: • 20 min read

I’ve been working on a new real-time strategy game called Burnt for Beacons. It is set on a frozen planet covered in snow. Every unit in the game leaves tracks that slowly fade as snowfall reclaims them. The tracks aren’t just set dressing – they are critically important to the game: your opponents uncover previously carved tracks revealed through the fog-of-war to learn where you have been and where you are going, potentially giving them a decisive edge.

I’ve set out with a handful of goals and constraints:

  • Tracks last around 5 minutes before the snowfall buries them.
  • Tracks are per-player knowledge: what you’ve seen and what your opponents have seen may not be the same.
  • Replays are seekable: you can skip to any part of the replay within seconds.
  • Replays should be at most a few tens of MB.
  • The largest maps are up to 5km Ɨ 5km with ~10,000 units and 16 players.

While the scale target in the last point is something seen in other RTS games (e.g. Beyond All Reason or Supreme Commander), the combination of all of these presents unique technical challenges: How do you render 5 minutes of tracks for 10,000 units? How do you store them? How do you rapidly restore them during a replay without making the replays huge?

This post goes into technical detail of the last couple of days of work on this system, taking it from the initial implementation that used 384MB to only cover at most 4% of the map and with no replay seek support to meeting all the goals with just a few hundred MB of RAM for the whole map and up to 1MB/min in replays in the worst case.

How other games do it

Most games that leave tracks use one of two tricks, and they only work because tracks aren’t as critical to the game.

Decals that fade. The most popular approach, particularly in RTS games, is where each stretch of track is a textured quad on the ground that fades out over a lifetime. Beyond All Reason on the Recoil engine is a good example. Tracks lay a stretched quad as the unit moves in one direction and it fades over tens of seconds. Tracks are only created when the unit is visible. As a purely visual track system, this works perfectly fine for BAR.

Tank tracks left as fading decals in Beyond All Reason

A deformation map around the camera. Third-person games with deep snow keep a heightmap centred on the camera, render the player and nearby characters into it, and let the window scroll as the camera moves around. Outside of an area (~50m x 50m) tracks are dropped. The idea has been around for a long time and it’s still the approach in God of War Ragnarƶk (GDC 2023). It works really well when there’s only a handful of characters in a relatively small active area.

Footprints carved into deep snow in God of War Ragnarƶk

Unfortunately, neither of these really works for our game:

  • The volume is too high for decals. At 10k units a single tick lays 4,000 to 14,000 stamps. Five minutes of persistence means tens of millions of live marks: far too much to render.
  • We can’t limit to just where the camera is. As a critical component of the gameplay, the tracks need to be placed whether you were looking or not.
  • Storing a complete heightfield is impractical. At 5km Ɨ 5km with ~10cm granularity even 8-bit height resolution with the naive approach is 2.5GB, much more than we’d want to budget for tracks alone.

Three ways to keep tracks: fading decals, a camera window, and a tiled field

Where it started: a fixed GPU pool

Until yesterday the whole track system lived on the GPU. It started as a 16-bit heightfield with virtual pages and a cap on the number of active pages. There were two maps:

Map Coarse layer Detail atlas
Used for Zoomed out, or no detail page Active tiles at normal zoom
Texel about 1.25m 12.5cm
Format RG16F RGB8
Size 4096² 8192² (1024 x 256²)
Layout Covers whole map 32m square tiles (4% of map, LRU eviction)

And because tracks are per-player, we also had two copies: the truth, and what you’d seen (local player only).

As units moved on the map, they would stamp their tread marks (with berms) onto the coarse map and then into the detail map as GPU draws, allocating (and evicting) a page if needed. This would happen even for off-screen units because it is important to be able to discover tracks even when you didn’t witness their creation.

This worked well enough in small skirmishes with hundreds of units, but simply could not work at scale.

  • The detail pool covered only around 4% of a 5km map so pages were constantly evicted.
  • Despite only serving 4% of the map, it still used 384MB, which is tolerable, but way too big for 4%. There’s no simple way to scale this up.
  • Changing player in replay views was incorrect since it only showed what the player saw since the change.
  • Replay seeks were slow: tracks stamping over the past 5 minutes had to be replayed, taking several seconds in larger games.

The animation below shows an example of how this worked: new tracks were constantly churning the detail atlas, often leaving the camera looking at the coarse texture map, which did not meet the target visual quality.

The GPU only needs what it sees

If we look back at how other games approach this problem, you see two approaches with different trade-offs:

  • Height fields (our detail maps) are cheap to render, but expensive to store.
  • Decal lists (our stamps) are cheap to store, but expensive to render.

However, we don’t need to render all tiles at once. Only when zoomed fully out can you see the whole map, and the coarse layer is fine for that (and not too expensive). When zoomed in, you can only see a small fraction of the map, so there’s no reason for the detail map to be the source of truth for everything: we only need it for what you can see.

So what format do we use for storing off-screen track data? It needs to be more compact than texels by ~10x, but also relatively cheap to update since units are moving whether you are looking at them or not.

One idea was to keep an 8-bit, 12.5cm texel snapshot for live tiles (on the CPU), but compress them when quiet. A quick test with zlib on a sample AI match showed that tiles on average compress 14x, which was small enough. Some early benchmarks also showed that we could actually rasterise the tread stamps on the CPU for 10k units with relatively low cost (more on this later).

Unfortunately, average case is not worst case. Problems with this approach arise when units are moving all over the map: we need to compress to keep memory low, but you can’t stamp into a compressed map, so either you keep everything decompressed (huge memory) or you have to constantly decompress/stamp/compress again, which is far too slow even for the fastest compressors.

Storing tracks

Rather than trying to keep everything in a texel format (compressed or not), the next idea is to just keep the stamps themselves, in a log, and only turn a tile into texels when something needs to look at it.

We still need to do this efficiently though: 10k units can lay a lot of track in 5 minutes. The fastest units at the moment move ~20m/s. That’s 60,000km of track. At 10Hz granularity it’s 30 million track segments. A naive data structure of start/end vectors, timestamps, treadtype, etc. can easily be tens of bytes and push us over a GB, which is unacceptable. That’s ignoring any data structure overhead.

The approach we settled on:

  • Quantize coordinates to ~0.1cm (1/1024m)
  • Predict next position based on velocity and then use a variable length delta encode:
    • 2 bytes: for steps up to ~6.3cm - typical when cruising in straight lines
    • 3 bytes: for steps up to ~50cm - typical when jostling in battle
    • 4 bytes: step up to 4m - rare.
    • 10 bytes: whole keyframe, e.g. starting again after a stop.

These are written into blocks of up to 255 points to amortise data structure overhead and each 32m tile keeps a 12-byte reference to every block that touches it.

This works great: at just a few bytes per stamp on average, even with 30M stamps that’s under 100MB.

Ok, so how do we render this? When a tile comes into view, we then turn these stamps into texels again by rasterising the stamp list into the 256² texture and upload to the GPU. In typical scenes, we can do this relatively cheaply by stamping on the CPU and just budgeting how much stamping we do per frame. The GPU only keeps the 500 closest tiles.

Unfortunately, during dense battles a single tile can collect tens of thousands of stamps over 5 minutes and re-laying them when the camera moves over can be very slow. To combat this, we go back to our previous idea of storing texels again! Once an individual tile’s log passes a threshold of stamps (say, 10000) we eagerly rasterise it down to a texture and then pass it through zstd to losslessly compress it. Only newer stamps stay in the log. We also flatten tiles early if total log memory reaches a threshold to keep total work bounded. This strikes a good balance between memory and re-lay cost.

In the worst scenarios it can take a few frames for the view to catch up, but this is unnoticeable in practice since the camera is moving and the centre-most tiles fill in first.

Per-player knowledge

With every stamp on the CPU, each player’s view of the tracks becomes a rule instead of a second texture to keep in sync. The replay indexer records when each player last looked at every 8 m cell (10.8 MB for a 15-minute, 16-player match). A track is in your seen copy if you looked at its cell at or after the tick it was laid.

In live play, seen is updated by copying truth into it wherever you have vision. A replay, or a tile rebuilt from the log, lays the same stamps through the same rule on the same grid, so switching players in a replay now shows exactly what that player knew. A seen tile that’s identical to truth shares truth’s memory, and an observer keeps no seen copy at all.

Making stamping cheap

A tread stamp is an oriented rectangle along the path the unit just drove, about 2.8m across for a typical unit. Each texel takes the max of itself and a berm (the lip of snow pushed up beside each tread) and then the min of that and a trench (the rut, with a cleat ridge every 0.3m). Every 0.6m a unit lays the new stretch plus a second, trench-only stamp over the previous one, so the new berm doesn’t refill the old rut. At 10k units that’s 4,000 to 14,000 stamps a tick, and they overlap heavily, so every track texel gets evaluated four or five times.

With the log, most of those stamps aren’t laid when they arrive. Only the raw tiles near the camera take their stamps live, and everything else waits until a tile is rebuilt as the camera reaches it, a busy tile is flattened, or a replay seeks. Watching a 1k-unit battle with every unit on screen and moving is roughly 400 to 1,400 live stamps a tick. The bursts are what hurt: a camera jump to a busy base rebuilds 174 to 252 tiles at once, each re-laying everything in its log, and a seek re-lays five minutes of tracks across the whole map.

My first port of the stamp shader to D cost 88µs a stamp, and that version laid every stamp the moment it arrived, so replaying a 10k-unit match ran at 3 fps. Some quick wins cut that by about 5.6x. Then I spread the work across threads: each batch of stamps is bucketed by tile and the tiles are laid in parallel. Tiles never share texels, so there are no locks and the result is identical to laying them one at a time. That’s still the same amount of work, just spread over more cores, so the rest of this section is about making each stamp cheaper.

Prebaked sprites. The bigger win was not evaluating the shape at all at run time. Every gear’s shape is baked once into small sprites, each covering one 0.6 m step of track, at 64 headings and a handful of noise seeds. A stamp then lays the sprites centred on every multiple of 0.6m along its path, and each texel is just o = min(max(o, berm), trench).

One sprite's berm and trench, and the result laid on flat snow

A few details make that hold together:

  • 0.6 m is two cleats, and every sprite is baked centred on a cleat boundary, so neighbouring sprites’ cleats line up under the min instead of erasing each other.
  • The seed is a hash of the sprite’s index along the path, not a random draw. A replay re-lay lays exactly the same sprites, so per-player belief stays exact.
  • 64 headings is 5.6° apart, which at the end of a 0.6 m sprite is under a texel of error.

Serial cost on the 10k-unit replay (11.2M stamps) went from 15.7 to 1.21 µs a stamp, 13Ɨ.

Then the inner loop. The first version scaled each sprite texel by the tile’s fade gain as a 16.16 fixed-point int, which widened every lane to 32 bits, and the release build kept a bounds check per lane. Rows are only about 20 texels wide, so even vectorised code spent its time on tails and on runtime checks for overlapping slices. The fixes:

  • Fold the tile’s fade into its texels the first time it’s written in a fade step, so the loop has no scale at all.
  • Pad every sprite row to a multiple of 8 with neutral texels, and lay a sprite that sits wholly inside its tile as a fixed-width block. LDC then emits ldp q / smax.8h / smin.8h / stp q on ARM and pmaxsw / pminsw with SSE2 on x64: four vectors a row, no tail.
  • Give each worker a last-hit pointer into the sprite cache, which had a mutex the workers were contending on.

Here’s the D for a whole-sprite block. W is the sprite’s row pitch, 32 texels for the Wolverine:

void layBlock(uint W)(short[] o, size_t at, size_t stride, const(short)[] berm,
        const(short)[] trench, uint v0, uint v1, bool withBerm) @trusted pure nothrow @nogc
{
    foreach (v; v0 .. v1 + 1)
    {
        short* row = o.ptr + at + v * stride;
        const(short)* b = berm.ptr + v * W, t = trench.ptr + v * W;
        short[W] x = row[0 .. W];          // a local copy: nothing can alias it
        if (withBerm)
            foreach (i; 0 .. W)
                x[i] = x[i] > b[i] ? x[i] : b[i];
        foreach (i; 0 .. W)
            x[i] = x[i] < t[i] ? x[i] : t[i];
        row[0 .. W] = x[];
    }
}

And the whole inner loop LDC 1.41 makes of layBlock!32 for x86-64 at its SSE2 baseline (-O3 -release, no -mcpu). One iteration is one 32-texel sprite row: four 8-lane vectors of the tile, four of berm, four of trench, eight instructions of real work.

LBB36_5:                          ; one sprite row
    movl    %r8d, %esi
    andl    $-32, %esi
    addq    %rsi, %rsi            ; byte offset of this row in the sprite
    movdqu  -48(%rdx), %xmm0      ; tile row, texels 0..7
    movdqu  -32(%rdx), %xmm1      ;           8..15
    movdqu  -16(%rdx), %xmm2      ;           16..23
    movdqu  (%rdx), %xmm3         ;           24..31
    movdqu  (%r9,%rsi), %xmm4     ; berm
    pmaxsw  %xmm0, %xmm4          ; max(tile, berm)
    movdqu  16(%r9,%rsi), %xmm0
    pmaxsw  %xmm1, %xmm0
    movdqu  32(%r9,%rsi), %xmm1
    pmaxsw  %xmm2, %xmm1
    movdqu  48(%r9,%rsi), %xmm2
    pmaxsw  %xmm3, %xmm2
    movdqu  (%rax,%rsi), %xmm3    ; trench
    pminsw  %xmm4, %xmm3          ; min(that, trench)
    movdqu  16(%rax,%rsi), %xmm4
    pminsw  %xmm0, %xmm4
    movdqu  32(%rax,%rsi), %xmm0
    pminsw  %xmm1, %xmm0
    movdqu  48(%rax,%rsi), %xmm1
    pminsw  %xmm2, %xmm1
    movdqu  %xmm3, -48(%rdx)      ; store the row back
    movdqu  %xmm4, -32(%rdx)
    movdqu  %xmm0, -16(%rdx)
    movdqu  %xmm1, (%rdx)
    addq    $32, %r8              ; next sprite row
    addq    %rcx, %rdx            ; next tile row (stride)
    decq    %rdi
    jne     LBB36_5

No tail, no bounds checks, no widening: 16-bit lanes from load to store. The trench-only stamp gets its own copy of the loop with the pmaxsw half gone.

That took LDC from 1.21 to 0.74 µs a stamp, or 2.6 ms a tick across the workers if every stamp at 10k units were laid as it arrived.

Replays

A replay is just the command stream, re-run on the deterministic sim. To seek, we restore the nearest keyframe and simulate forward from there. Tracks aren’t part of the sim, so they come from a separate path history recorded alongside it, and a seek re-lays the last five minutes of it. Having the whole path history allows us to recreate per-player belief information on demand.

A seek restores the nearest keyframe and re-lays five minutes of tracks

Path history. This was a polyline per unit at 32 bytes a vertex: 294 MB for a 10-minute 10k-unit match, far too much. It’s now 10.1 MB, about 1 MB a minute.

Path history: 294 MB to 10 MB for a 10-minute 10k-unit match

  • Fewer vertices. A vertex is only kept where a straight line from the last one would stray more than 15 cm from where the unit actually drove. Any looser and the lines visibly cut corners. Units in a fight turn a lot, so this only took 9M vertices down to 4.9M.
  • Predict each vertex, store the miss. Units tend to keep going the way they were going, so each vertex is predicted by carrying the last line on, and only the miss is stored, on a 10 cm grid.
  • Entropy-code the misses. The misses are small and mostly zero, which is exactly what an adaptive range coder is good at: about 2.2 bytes a vertex.

Seeking at 10k units decodes just the last five minutes of path history (about 0.3s, however long the match) and re-lays the tracks. Currently this is done all upfront on seek rather than lazily like during the game, but that will be fixed soon.

Where it landed

This all landed over the past few days and is working well! There’s more work to improve the speed of the replay seeking and potentially optimise some of the most pathological cases, but it is in a usable state and I’m happy with this and it’s hitting all the targets.


Posted: • 13 min read

There’s a current trend of LLM-authored software moving away from programming languages designed for human ergonomics (e.g. Python) towards those with other upsides such as higher safety, performance, or iteration speed. From what I’ve seen, many people are rewriting various parts of the software stack in Rust for this reason (Bun, PokĆ©mon Showdown, the TypeScript compiler): it produces fast, safe code and the usual frustrations around having to satisfy the borrow checker may matter less to AI agents. The agentic experience (AX) does not necessarily match the human experience, so we have to revisit our assumptions around what matters in language design.

I’ve been a long-time fan of the D programming language, so my natural inclination here is to look at how D fares as a language for agent engineering. I do believe it has the potential to be a great language for agents (fast, safe code, rapid compilation, powerful abstractions). I’ve been using D with Claude for a long time now and the vibes are good, but vibes are not data: how well does Claude actually work with D? Where does it trip up? How can D evolve to be better for agentic software development?

Fortunately, unlike with humans, it’s quite easy to run relatively large experiments with agents in a controlled manner. In this post, I’ll be exploring how Claude performs with D compared to Go on a set of synthetic problems from langbench.

The setup:

  • 40 synthetic real-world problems such as a JSON Schema validator library, or a card game simulator.
  • All using Claude Sonnet 5.5 in Claude Code.
  • Full test suite per problem available.
  • Asked to ā€œstructure it the way a well-maintained open-source D project of this kind would beā€ (or Go project), complete with unit tests.
  • Instructed not to use an existing library that solves the problem.

Overall, D does well, but does fall behind Go in terms of required output tokens and turns to produce a working solution. The difference is real and meaningful, but modest, and much of the difference is solvable.

D relative to Go: output tokens 1.13Ɨ, turns 1.38Ɨ, cost 1.19Ɨ, with 95% intervals

The rest of this post will get into details of where the differences are and what the D language and ecosystem can do about it.

D relative to Go

The ratios are computed by taking the median over repetitions of the same problem, dividing D by Go, and taking the geometric mean across all problems with a 95% bootstrap interval. Output tokens are the headline number here since they measure how much the agent had to write and think, independently of how it batches commands into turns. D took quite significantly more turns largely due to language-specific costs, but those tended to be cheap edit-build-test loops rather than e.g. significantly more thinking. Ultimately, D costs more because the agent was doing more edit-build-test loops.

D relative to Go Value
Output tokens (paired per problem, 95% CI) 1.13Ɨ (1.08–1.19)
Turns 1.38Ɨ (1.26–1.52)
Cost 1.19Ɨ (1.13–1.25)
Calls spent on language-specific costs D 290, Go 26

Where the extra calls go

The cause of the extra turns was identified via agentic reviewers reading the D and Go session transcripts side-by-side and categorising each tool call into one of four buckets:

  1. Productive work, e.g. writing code.
  2. Language-specific costs directly attributable to a language-specific papercut.
  3. Language-agnostic costs, e.g. wrong expectations in an agent’s own tests, shell slip-ups, etc.
  4. Discretionary work after the task was done.

The key takeaways are that while D does end up using extra calls for productive work, the majority of the difference is D-specific papercuts. Every D session hit at least one D-specific cost.

Tool calls by kind: D 894 productive, 290 language-specific, 293 any language, 154 discretionary (1,631 total); Go 785, 26, 259, 111 (1,181 total)

D’s specific costs

Within the language-specific costs for D, we further categorised them into 14 sub-buckets to understand common D-specific papercuts that agents were hitting. The top four account for nearly two thirds of D’s language-specific costs. Some were broad-and-shallow, affecting many sessions lightly, while others were narrow-and-deep, impacting a small number of sessions significantly.

Note: many of the issues are actually in the tooling rather than the language itself.

D-specific overhead in calls by category, with the number of sessions that hit each

Unit-test failures without values

By far the biggest issue is that, by default, D unit test failures only tell you that an assertion failed (e.g. assert(x == y)) and do not tell you what the values of the compared variables were that led to the failure. This caused the LLM to add extra print statements or grep output to find what actually happened. Not expensive, but it does cost an extra few turns and slows things down.

D has a solution to this with -checkaction=context but Claude didn’t find it on its own. A clear indication of how important defaults are!

In addition to missing context, each test module stops at its first failure, so working through N failures often takes N iterations. By comparison, Go’s test runner lists every failure.

D example (default):

core.exception.AssertError@tests/test_cpu.d(103):
  Assertion failure
----------------
??:? _d_assert [0x104f7d7ef]
…/tests/test_cpu.d:103 void
  test_cpu.__unittest_L100_C1()
??:? int rt.minfo.moduleinfos_apply(…)

D with -checkaction=context:

ca.d(2): [unittest] 3 != 4
1/1 modules FAILED unittests

Go example:

--- FAIL: TestMemoryOps (0.00s)
    chip8_test.go:156: BCD memory: 234 1 2
--- FAIL: TestFX1EAndFX29 (0.00s)
    chip8_test.go:167: I=0x10fe, want 0x10e
--- FAIL: TestTimerTick (0.00s)
    chip8_test.go:208: DT=7 ST=0, want 7 7
--- FAIL: TestDrawCollisionAndZeroRows (0.00s)
    chip8_test.go:244: VF=0 lit=2

dub’s unittest configuration

The prompt asked for ā€œunit tests for the library, in files separate from the library sourceā€. That is less common in D, where unit tests usually live alongside the code they test, but dub handles it fine, and the Go prompt asked for the same. What happened in just over half of the D sessions is that the agent built a unittest dub configuration that didn’t have a main, and then dub test failed with an undefined symbol error at link time for _main.

The fix is to use targetType "library", but it often took agents a few attempts to find it.

Undefined symbols for architecture arm64:
  "_main", referenced from:
      <initial-undefines>
Executable configuration "unittest" of package
sqlitefile defines no main source file

NaN-initialised floating point

A justified, but unusual, aspect of D is that floating point values are default initialised to NaN, e.g. with new double[n]. The idea is that if you forget to initialise then NaN is the most likely thing to cause your program to fail so that you learn quickly that you forgot and go back and properly initialise. Other languages either force explicit initialisation (which requires more sophisticated static checking), or default initialise to 0.0, which is often correct/expected, but sometimes just means that you forgot to specify the initial value and things just surprisingly worked with the default. It’s a deliberate but contentious decision that D makes.

Unfortunately, it is one that tripped up the agent in one task in particular. In all three SAT solver runs, the agent didn’t realise this, and the solver never finished, running until it hit the test suite’s 10-minute limit. Each time, it took quite a while to debug. It also caught out the SVG rasteriser, more briefly. Perhaps a niche case, but anecdotally it is something I’ve seen Claude hit in other contexts as well.

Attributes the agent adds itself

Claude likes to add @safe, pure, nothrow and @nogc in its D code. This is arguably a good thing, but it does then spend quite a few turns fixing the inevitable type checker failures. Self-inflicted, but this appears to be what Claude does with D.

The actual failures themselves were varied:

Smaller language frictions

There were also a number of smaller frictions:

  • const / immutable: const(Value) can’t become Value for concatenation, so the agent strips const across the codebase
  • rvalues to ref: resolve(Registry.parse(text)) where resolve takes ref const Registry. D compilers already accept this with -preview=rvaluerefparam.
  • Names that clash with the implicit object module or a package: capacity; a class named ModuleInfo, dozens of conflicting-symbol errors; function inflate in package inflate.
  • Keywords as names: macro is reserved but unused, and natural in a template engine; real() gives a parse error pointing elsewhere.
  • Runtime semantics: appending after shrinking .length reallocates every time, making a JSON parser quadratic, 6.22 s → 0.06 s once fixed; readText of an empty file returns null; deep-recursion tests overflow the unittest runner’s 8 MB stack with only exit code āˆ’11.
  • Phobos: to!double misrounds on arm64, so a shortest round-trip printer showed 0.3 for 0.1 + 0.2; relativePath returns relative paths unchanged.

A compiler bug, again

We also managed to hit an LDC-specific compiler bug that cost some turns. In certain scenarios, an exception can escape a catch incorrectly (only tested on arm64 macOS):

class E1 : Exception { this() { super("e1"); } }

void gen(int op)
{
    if (op == 0)
        throw new E1;
    try
        gen(0);
    catch (E1 e)
    {
    }
}

void main()
{
    import core.stdc.stdio : puts;
    try { gen(1); puts("ok: swallowed"); }
    catch (E1 e) puts("BUG: escaped");
}
$ ldc2 bug.d && ./bug
BUG: escaped

By problem

Compared to Go, there was notable variation across different problems in terms of number of turns. SAT was an outlier due to the NaN issue, and a handful required fewer turns than Go.

Tool calls summed over each problem's runs, D minus Go, for all 40 problems

What would make D cheaper for agents

Based on these results, we can make a few suggestions to the D ecosystem for how to make Claude more effective at writing D:

Change Where Calls Sessions Discussion
-checkaction=context under dub test; report every failure dub, druntime 71 29 dub#2296, forum, dmd#19992, dmd#19576
Executable unittest configuration without a main dub 42 31 dub#1270, dub#2060
Catch reads of NaN-initialised floats compiler, D‑Scanner 38 4 forum (2012), forum (2026)
Infer attributes for non-template functions compiler 37 23 DIP idea
Rvalues to ref by default (-preview=rvaluerefparam) language 12 9 DIP 1016, dmd#22078
Let explicitly imported names take precedence over the implicit object module (capacity, ModuleInfo); un-reserve macro language, druntime ~20 ~15 forum (macro)
LDC exception-escape bug; arm64 to!double LDC, Phobos 16 2 ldc#4433 (to!double)

In the short term, as a mitigation, it is likely that some simple Skills that remind agents of these papercuts could meaningfully help their effectiveness.

How this was measured

  • Run: D (LDC 1.41.0, dub 1.40.0) and Go 1.27.1. All 40 langbench problems, with ten of them (bigint, buildsys, chip8, datalog, depresolve, jq, regex, sat, toml and webhooks) run three times: 120 sessions total, 60 per language. After the run, three problems (mime, fulltext, svgraster) had test data replaced for licensing reasons, and their six sessions were rerun; the effort numbers above use the reruns.
  • Agent: Claude Sonnet 5.5 at high effort in Claude Code; one headless session per task in a private sandboxed workspace; no personal settings, memory or MCP servers; the same prompt apart from the language’s name and toolchain.
  • Correctness: each project rebuilt from a clean copy of its sources and run against the public tests, plus held-out tests (never shown to agents) for the five large problems.
  • Classification: all 2,812 tool calls of the original 120 sessions (before the six reruns) labelled by eight reviewers with shared instructions, reading D and Go sessions of the same problem side by side; large incidents rechecked against transcripts; the compiler bug reproduced.
  • Limits: one model, one harness, one platform (Apple Silicon/macOS). The productive/overhead boundary is uncertain by about one call per session; categories under five calls are anecdotes. Most problems ran once, so per-problem numbers are noisy.
  • Earlier run (different prompt, agents in a personal environment): D-specific costs were 62% of the gap then and 59% now, with the same causes recurring. Both prompts asked every language for unit tests in separate files.

Conclusion

I’m excited that we’re entering an era of software development where we can answer empirical questions more accurately and easily, where we once had to rely on anecdotes or small, often flawed, studies. I’d certainly not consider this run at the calibre of empirical quality that I’d like, but it’s a good starting point.

Some things I may pursue next:

  • Try different models, effort levels, harnesses.
  • Even larger problems, perhaps on established code bases with >100kLOC.
  • Timed measurements that also account for build time, run times.
  • Test out the impact of Skills that mitigate known issues.
  • Try different prompting strategies to guide agents in different directions, e.g. ā€œkeep things simpleā€, or ā€œefficiency is importantā€.
  • Use a harness like this for evaluating new language features: wouldn’t it be nice if a language proposal came with an ā€œif implemented, agents use X% fewer tokens in benchmark Bā€?

Posted: • 7 min read

I’ve never really gone very deep into graphics or rendering, but I’ve long been quite fascinated by the use of signed distance fields for defining geometry and implicit surfaces more generally. Like many people, I found out about this through Inigo Quilez’s work and Shadertoy in particular. A long time ago I did spend some time playing with it. I’d like to create more if I find the time / inspiration.

What I like most about SDFs for defining geometry is that simple geometry can be expressed simply. A sphere is defined with just a couple of mathematical operations:

float sphere(vec3 p, float r)
{
  return length(p) - r;
}

Compare this to regular triangle meshes where you can’t even define an exact sphere and trying to approximate it requires a huge number of vertices. This is not too difficult to define programmatically, but you are essentially forced to use authoring tools to deal with the complexity of defining geometry, no matter how simple. Many times when I’ve been prototyping game ideas, I’ve been frustrated that I’m forced to open up Blender just to create the most trivial piece of geometry.

What I’d really like is just some textual format for defining geometry similar to how you do it with SDF. OpenSCAD is there for CSG, but as far as I can tell you can’t do anything like smooth unions or domain transformations, which are needed for more organic-looking geometry. Using pure shader code is ok for this, but with shapes being represented as functions, transformations really need a language that supports first class functions (an SDF is a function of ā„Ā³ā†’ā„, then a union transformation is (ā„Ā³ā†’ā„)→(ā„Ā³ā†’ā„)→(ā„Ā³ā†’ā„)).

Finally, with LLMs in the picture, as cool as Blender MCP is, it would be nice if the LLM could just spit out a textual scene format. I tend to agree with Carmack here:

To that end, I started playing around with an idea of an SDF-based file format. As far as I can find, there isn’t really anything like this (which was quite surprising!). Would be interested to know if something like this exists.

The basic idea is that you can define shapes textually via simple primitives, transformations, and operations:

# Define sphere at origin, and rotated cube.
shape s = sphere(radius: 2);
shape b = box(width: 3, height: 3, depth: 3) |> rotate(x: 100, y: 200, z: 100);

# Translate and then combine via smooth union.
# As the last expression in the file, this is the output shape.
smooth_union(
  s |> translate(x: -1, y: 0, z: 0),
  b |> translate(x: 1, y: 0, z: 0),
  k: 1.0
);

This file defines the shape. I haven’t put a lot of thought into syntax yet, but the shape type here actually is an SDF, and we have primitives such as sphere and box as leaf nodes and higher-order SDFs such as translate and smooth_union for transformations.

With geometry defined this way, you can then render via a simple tool that understands how to parse the format. The tool does basic parsing and semantic analysis producing a runtime data model that supports querying the field at any coordinate. The tool also supports rendering using basic raymarching (its only function right now).

sdftool demo.sdf -o demo.png

This produces:

Example output of SDF tool defined earlier

Since we have an analytical shape, we can also extract normals via tetrahedron technique.

sdftool demo.sdf -o normals.png --render-mode normal

Example of rendering normals

If we need a mesh, we can generate one (currently using marching cubes with basic QEM simplification):

sdftool demo.sdf -o mesh.obj --mesh

Example of generated mesh

With this language in place, I can quite easily generate non-trivial meshes purely with text such as a chess pawn with smooth curves:

shape base = cylinder(radius: 1.4, height: 0.35) |> color(0.4, 0.35, 0.33);
shape base_rim = cylinder(radius: 1.2, height: 0.15) |> translate(y: 0.45);
shape stem = cylinder(radius: 0.36, height: 2.4) |> translate(y: 1.5);
shape mid_stem = cylinder(radius: 0.7, height: 1.4) |> translate(y: 0.5);
shape collar = cylinder(radius: 0.78, height: 0.01) |> translate(y: 2.7) |> expand(0.04);
shape head = sphere(radius: 0.7) |> translate(y: 3.5);

shape base_assembly = smooth_union(base, base_rim, k: 0.1);
shape mid = smooth_union(base_assembly, mid_stem, k: 0.4);
shape lower_pawn = smooth_union(mid, stem, k: 0.5);
shape pawn_collar = smooth_union(lower_pawn, collar, k: 0.1);
shape pawn = smooth_union(pawn_collar, head, k: 0.30);

translate(pawn, y: -2.5);
Chess pawn normals Chess pawn mesh

Another benefit of this format is size: the raw text for this pawn mesh is just 757 bytes, and this is without any attempt at compression. Could easily be under 100 bytes with minimal effort. The mesh by comparison is a few hundred kilobytes.

Of course, there are downsides to SDFs: rendering SDFs directly is still very expensive and complex geometry may end up being extremely difficult to model this way.

There are some future directions I’d like to take this:

  • A runtime library could load the file and support an API for evaluating the field at points, or raymarching.
  • The library could also allow creating the data format in memory at runtime.
  • Build more scaffolding to allow LLMs to create geometry from a prompt.
  • Support approaches to texturing.
  • And of course, improved algorithms for mesh generation and rendering.

Will continue tinkering on this and if it proves useful will maybe open source.


Posted: • 4 min read

I’ve been getting back into a bit of D programming recently and catching up on what’s been happening in the community. Some things have changed (Andrei isn’t around any more), but most things have stayed the same. Walter is still around and the language has a small and loyal following. DConf is still happening every year and people are still shipping things.

It is significantly smaller than both Rust and Go though. I think this is a real shame since I do feel that D fits a niche of languages that give you systems level access with quite powerful features around expressiveness and generally pleasant (and familiar) syntax. By comparison, I find Rust a bit too opinionated on how it should be written (yes, the borrow checker) and while Go is pleasant, it’s not very powerful when it comes to setting up scalable abstractions. D fits the gap quite nicely (while having problems of its own).

A perennial problem that D seems to have is that it can’t quite decide what it wants to be, and as a result tries to please everyone. As an example, D has always had a GC, but you get a subset of devs that really want to avoid the GC (for legitimate reasons). As a result, a long time ago, D added the @nogc attribute to functions, which statically checks if the function may allocate memory. The idea is that you can wrap your latency sensitive code (e.g. a game’s update loop) in @nogc and then rest assured that you will avoid GC pauses.

// Simple @nogc function - this compiles fine
@nogc int add(int a, int b) {
    return a + b;
}

// This won't compile - array literals allocate
@nogc int[] getNumbers() {
    return [1, 2, 3];
}

On the surface, @nogc is fine, but now you have a problem with what to do with common libraries: do they use the GC, avoid the GC, or provide the option of GC/no-GC? Whatever you choose, you are not going to win: either deal with endless complexity of supporting both, or make one camp unhappy.

I was not a fan when @nogc was originally proposed and I still think it was a mistake. I should mention that as a game developer, I do often want to avoid the GC!

I’d much prefer that D did not implement @nogc and instead:

  • Provide runtime tooling that helps you find GC allocations.
  • Try to avoid GC as much as possible in the standard library.
  • Continue to provide language features / utilities to avoid GC when needed.
  • Continue to invest in improving the GC pause times.

If you are a fan of @nogc, I’d further offer some other observations:

  1. If you care about minimising pauses in your application, GC is only one source of those. You have to also avoid any sort of non-wait-free locks or concurrent data structures / blocking syscalls / pauses from reference counted deallocation cascades.
  2. Modern GC implementations can get those pauses down <1ms (see Go as proof of life). This tech continues to improve, so it is a good bet.
  3. You can achieve 99% of the desired outcome via runtime tooling (logging on each GC allocation). I’ve done a lot of work in Unity3D to avoid GC in C#. Yes, it does take some effort to track down those allocations and fix them, but really the work is not that different from fixing compilation errors from @nogc, and you have the option of just ignoring the GCs that happen on the rare paths that you don’t really care about.

All this being said, @nogc has shipped and I would never advocate for breaking existing code. However, there are active discussions going on about a ā€œPhobos 3ā€ and I would suggest that the approach is to go all-in and assume GC. Standard containers should just use GC unapologetically (but responsibly). There’s nothing stopping someone from creating an allocator-based container library and putting it on dub, but it doesn’t need to be in the standard library.

I continue to believe that D has its place in the set of useful and unique programming languages and really ought to have more usage. Complicating the language / compiler / libraries in order to try and make everyone happy I think goes against the pragmatism embodied by D and just stretches already thin contributor resources. Stay simple, choose a 90% solution over 100%, and focus on quality of what’s already there.


Posted: • 3 min read

Often when building APIs we’d like the caller to provide some information in a format, or using a protocol defined by the library. For example, we might want access to a contiguous buffer specified by a (void*, size_t) pair.

void cool_feature(void* buffer, size_t len);

An API like this is fine if the buffer will be read synchonously, but sometimes we need asynchronous access. This introduces a lifetime problem: how does the caller know when it can free the buffer?

A common way to solve this is to provide a callback that will be invoked once the processing has completed:

void cool_feature(void* buffer, size_t len, void (*done)(void*));

Here, done will be called with buffer once cool_feature has asynchonously finished its work.

This works most of the time, but has a couple of problems:

  1. You need to remember to call done in all cases.
  2. It only works if done only needs to be called with the buffer pointer. What if my buffer is part of a larger object?
struct Object {
  // ...
  std::string buffer;
  // ...
};

void do_stuff(std::unique_ptr<Object> obj) {
  cool_feature(obj.buffer.data(), obj.buffer.size(), ???);
}

There’s no obvious choice of function to pass in. We want to free obj once buffer processing is done, but we’ll be given a pointer to the string data, not obj.

A possible solution is to pass in an std::function<void()> as the callback, so that obj can be captured and destroyed as necessary. This works, but std::function has difficulty with move-only types, and there’s no guarantees that a capturing std::function won’t allocate memory.

We could, of course, define another interface (maybe call it ContiguousBufferProvider), but this also requires an extra memory allocation.

A little trick we can do to handle most of the common cases is to pass in a type-erased context to the function.

using Context = std::unique_ptr<void*, void(*)(void*)>;

void cool_feature(void* buffer, size_t len, Context context);

The context is essentially an extra piece of baggage that must be carried around until the buffer has been processed. Once processed, we just drop the context and it cleans up after itself.

We can also benefit from an extra function that converts any object into a Context through type erasure:

template <typename T>
void deleter(void* p) {
  delete static_cast<T*>(p);
}

template <typename T>
Context erase_type(std::unique_ptr<T> p) {
  return Context(static_cast<void*>(p.release()), &deleter<T>);
}

With this, the Object example is easy to solve:

void do_stuff(std::unique_ptr<Object> obj) {
  cool_feature(
      obj.buffer.data(),
      obj.buffer.size(),
      erase_type(std::move(obj));
}

This guarantees no extra memory allocations, and cool_feature just needs to drop the context once finished.

There are probably more general ways to solve this, but I like this approach as it is clean, simple, and solves all the problems I’ve encountered so far.