Newsletter #130
Enjoy Newsletter #130.
How Anthropic runs large-scale code migrations with Claude Code
Migrating a large codebase to another language used to be a multi-year endeavor undertaken only as a last resort. Anthropic shows how that calculus has changed: Bun migrated one million lines of code from Zig to Rust in under two weeks, consuming roughly 5.9 billion input tokens and 690 million output tokens (around $165,000 at standard API pricing). In return, the entire existing test suite passed before merging (19 regressions surfaced afterward and were all fixed), the binary shrank by 19%, runtime performance improved by 2–5%, and one memory benchmark dropped from 6,745 MB to 609 MB. In another example, 165,000 lines of Python were migrated to TypeScript over a single weekend.
The workflow follows six steps: author a translation rulebook alongside a dependency graph, pilot the rules on a sample batch of files, translate the codebase in parallel using worker agents, run a compilation loop pairing a fixer agent with an adversarial reviewer agent, run fast tests to catch runtime bugs, and finally verify behavioral parity against the original implementation. The core lesson is to fix the generation loop rather than hand-patching generated code: whenever a mistake repeats, update the rulebook and regenerate. Doing so requires an objective “oracle”—such as a compiler and test suite—up front, plus a resumable work queue. Compute spend should also be tiered deliberately: smaller models like Sonnet handle bulk translation, while larger models like Fable or Opus write the rulebook and perform adversarial reviews.
The VFS
Whether you read a file on ext4, a virtual file in /proc that exists only in kernel memory, or a remote file over NFS, you use the exact same system calls and file descriptor semantics. The layer that makes this possible is the VFS (Virtual File System), sitting between the syscall interface and concrete filesystems. This article explains the VFS as a textbook application of “program to an interface, not an implementation”—where, in C, an interface is simply a struct of function pointers. Four core objects do the heavy lifting: a superblock represents a mounted filesystem, an inode represents an object within it (a file, directory, or link), a dentry binds a name to an inode (since inodes themselves don’t know their own filenames), and a file represents a specific open handle held by a process with its own read/write offset. The super_operations, inode_operations, and file_operations tables hold filesystem-specific behaviors, falling back to generic VFS implementations whenever a hook is left unimplemented.
In practice, most work is handled by shared VFS code before ever touching a filesystem driver. When resolving a path like /etc/hostname, the kernel walks component by component and calls the filesystem’s lookup hook only when the dentry cache (dcache) misses. That cache even remembers nonexistent paths (negative dentries) and is read locklessly via RCU. Reading file contents works similarly: most reads simply copy bytes out of the page cache without touching the disk, and a user-space file descriptor is nothing more than an index into the process’s struct file * array.
Text Editor Data Structures
When building a text editor from scratch, the first question is how to represent file contents in memory. Cameron DaCamara starts by laying out his requirements: fast insertions and deletions, fast undo/redo, UTF-8 support, and simultaneous multi-cursor editing. From there, he systematically eliminates candidates. A single contiguous string is simple to render, but bogs down on files over 1 MB, reallocations can turn $O(n)$ edits into $O(n^2)$, and snapshotting for undo/redo burns memory. Emacs-style gap buffers are simple but poorly suited to multiple cursors. Ropes give $O(\log n)$ operations, but copy-on-write overhead bloats memory usage. Traditional piece tables, once used in Microsoft Word, hit contiguous-array bottlenecks during long editing sessions. VS Code’s piece tree combines the strengths of ropes and piece tables by backing the piece table with a red-black tree.
DaCamara takes that approach a step further by building an immutable piece tree called fredbuf. A purely functional red-black tree needs no parent pointers and allows cheap $O(1)$ snapshots at any point, turning undo and redo into two simple linked lists of tree roots. CRLF line-ending normalization is handled outside the tree, and a TreeWalker abstraction simplifies character iteration and correctness testing. Two takeaways stand out: analyzing constraints up front saves wasted effort, and investing in debugging tools—like visual tree dumpers—is what gets a complex project across the finish line, especially when implementing notoriously tricky immutable red-black tree deletions. The library is MIT-licensed and requires only C++20.
Scaling to 1 million concurrent sandboxes in seconds
Modal rewrote its entire sandbox control plane from the ground up and demonstrated the result with a striking milestone: spinning up one million concurrent sandboxes in under 60 seconds. Their previous architecture, much like Kubernetes, relied on strong consistency across the backend: every placement decision required global coordination, and database writes scaled linearly with sandbox count, making horizontal scaling impossible once demand reached millions of concurrent sandboxes and tens of thousands of creations per second.
The new architecture embraces decentralization. Instead of a single serialized central scheduler, multiple scheduler servers run in parallel using load-balancing algorithms over in-memory state. Each worker node becomes the source of truth for its own sandboxes, periodically publishing state to Redis rather than writing synchronously to a central datastore, removing Postgres from the sandbox creation hot path entirely. RPC calls that previously scaled per sandbox are coalesced into batches. As a result, creating a sandbox takes just two network hops and a single CPU operation with zero central coordination, achieving a median startup time under 500 ms and scheduling latency of just a few tens of milliseconds. The multi-month effort began with an intense prototyping sprint by four engineers before reimplementing every feature, monitoring pipeline, and container runtime detail—including tracking down and fixing Linux kernel rtnl lock contention when spinning up containers en masse.
Making 768 servers look like 1
When an application has to serve millions of queries per second over petabytes of data, a single database server is no longer enough. PlanetScale outlines three fundamental walls in single-primary scaling: writes always funnel into one machine because the write-ahead log (WAL) is a serialization bottleneck regardless of how many read replicas you add; replicas duplicate the full dataset rather than dividing it; and backing up or restoring a massive monolithic database can take hours or days. The solution is horizontal sharding—splitting both data and queries across many independent primary servers. In the article’s example, one petabyte is split across 256 shards of roughly 4 TB each, with one primary and two replicas per shard, totaling 768 servers.
To shield application developers from that complexity, a routing proxy layer sits between the app and the shards—Vitess for MySQL and Neki for Postgres. Unlike simple connection poolers such as PgBouncer, this router parses SQL queries, understands how data is distributed, plans and scatters queries to the right shards, and merges the results back together. The sharding topology is declared in JSON (a VSchema)—for instance, sharding the user table by a hash of its id column. Ultimately, the application connects to a single hostname like mydb.pscale.com: DNS resolves to network load balancers that distribute connections across stateless query routers, and the application never knows 768 database servers are working behind the scenes.
Branch‑Avoidant Programming
Modern CPUs speculate on which way branches will go to keep their instruction pipelines full; when a prediction is wrong, the pipeline must be flushed and refilled at a steep penalty. This article illustrates the cost by filtering numbers smaller than 500 out of a random array—a workload where the branch predictor is essentially guessing a coin flip. The trick is to eliminate the if statement: unconditionally write the current number into the output slot, and conditionally advance the output index with smlen += (numbers[i] < 500);. You perform extra writes, but they are far cheaper than branch mispredictions. Filtering 100,000 numbers 1,000 times on an Apple M1 takes 0.345 seconds with an if branch versus just 0.036 seconds branchless—nearly 10x faster; on an Intel Xeon, it drops from 0.576 to 0.110 seconds. Inspecting the assembly shows why: conditional jump instructions like b.gt (ARM) or jg (x86) are replaced by predication instructions like cinc or setle, keeping control flow completely straight.
Compilers don’t apply this transformation automatically because they don’t know the statistical distribution of your runtime data, nor can they safely assume that a conditional memory write is valid to execute unconditionally (since the destination buffer might only be sized for matching elements or could trigger a data race). Developers therefore have to write branchless loops deliberately when profiling calls for it. The author notes that quicksort partitioning is a prime candidate, as partitioning is fundamentally conditional data movement around a pivot.
Your Redis Leaderboard Is Probably Breaking Ties Wrong
Building a leaderboard with a Redis sorted set is a classic pattern, but few developers think about what happens when two players have the exact same score. By default, Redis breaks ties lexicographically by member string, meaning the player ID arbitrarily decides who ranks higher—deterministic, but meaningless to players. Common quick fixes have flaws of their own: millisecond timestamps collide under concurrency and suffer from clock skew across servers, while packing both score and timestamp into a single 64-bit IEEE 754 double eats into the precision and safe range of both numbers.
Podium, an open-source leaderboard service, implements a clean rule: whoever reaches a tied score first ranks higher. Each leaderboard maintains a monotonic counter initialized to the maximum signed 64-bit integer; whenever a player posts a new score, a Lua script decrements the counter and prepends that 19-digit number to the player’s public ID, ensuring earlier arrivals have a lexicographically larger prefix and sort ahead in descending queries. The script atomically updates four keys: the descending sorted set, an ascending sorted set (where counter digits are inverted so earlier arrivals still win ties), a hash mapping public IDs to internal member strings, and the counter itself. If a submitted score equals the player’s current score, their existing internal member name is preserved, making retries idempotent. The trade-off is roughly 11–17% higher write latency and 287 bytes per member instead of 99 bytes in local benchmarks—a reasonable price for fair, intuitive tie-breaking.
This post was rewritten by Claude Code with Opus 5.5 on 27/09/2026; reviewed and edited by Codex with GPT 6.1 Sol on 09/11/2026, and re-verified by Claude Code with Sonnet 5.5 on 16/11/2026.
Comments