Analysis of DHH's AI-Driven Rust and Elixir Rewrites Reveals Critical Thinking Still Required
Key point
The rewrites exhibited significant architectural inconsistencies and performance issues, such as a 1% notification delivery rate in the Rust version under heavy load, demonstrating that AI agents cannot replace human oversight in system design.
Details
AI-Generated Code Lacks Contextual Consistency
DHH (David Heinemeier Hansson) used AI agents to rewrite the Campfire Once application from Ruby on Rails into Rust, Elixir, and Go. An analysis by Piotr Sarnacki highlights that because the prompts lacked specific constraints, the AI made arbitrary architectural decisions. For instance, the Rust version dropped CSRF tokens and replaced Redis with in-process queues, while the Elixir version maintained closer backwards compatibility. These differences are not inherent to the languages but result from the AI's implicit choices, rendering direct comparisons difficult.
Performance Pitfalls and Benchmarking Flaws
The rewrites contained significant performance issues that a human developer would likely catch:
- Elixir: Used a single process for sequential SQL queries, ignoring potential concurrency for reads.
- Rust: Mixed async and blocking database operations within an async runtime, which can stall worker threads due to cooperative scheduling.
Initial benchmarks focused solely on throughput, leading to misleading conclusions. A test by Zach Daniels measured notification delivery rates under load, revealing a 1% successful delivery rate for the Rust version compared to 100% for the Elixir version. However, this was a closed-loop test. When re-evaluated with a constant arrival rate of 100 POSTs/s:
- Rust: Delivered ~14% of events with no HTTP errors, but disconnected lagging clients.
- Elixir: Delivered ~60% of events but timed out on ~23% of HTTP POST requests, with worst-case latency reaching 180s.
Trade-offs Require Human Judgment
The article argues that fixing the Rust version's delivery rate by increasing the tokio::sync::broadcast channel capacity from 256 to 16384 improved delivery to ~90% but increased pMAX latency to over 130s. The author contends this is a worse user experience than the original fail-fast approach. Meanwhile, the Elixir version consumed 1.8GB of memory during the stress test due to unbounded mailboxes. These examples illustrate that AI agents do not inherently understand trade-offs between latency, reliability, and resource usage, reinforcing the necessity for developers to critically evaluate and constrain AI-generated code.
This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.
Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.