DEV Community
Follow
Your codex exec is wasting ~900 ms per turn. I measured where.
The author rebuilt OpenAI's Codex CLI JavaScript harness using Bun, discovering architectural improvements rather than just runtime gains. The Codex engine has a Rust core with a JavaScript layer, which was replaced with Bun. A new client was introduced to sustain a single Codex app-server process, avoiding repeated spawns. Benchmarks revealed that a persistent process significantly reduced execution time compared to spawning a new one for each turn.A surprising finding was that release builds of Codex enable a telemetry exporter, which adds about 900 milliseconds to process shutdown time to upload metrics. This overhead is incurred with every turn if a new process is spawned. A simple configuration change, setting the metrics exporter to "none" in the config file, eliminates this delay without modifying the code.The performance gains from the persistent-process architecture were independent of the JavaScript runtime, as Node.js yielded similar results. Bun's advantages were primarily seen in its toolchain, significantly speeding up test startup and installation times. Initial increases in package size due to generated protocol types were addressed by consolidating declarations into a single file. This effort resulted in a smaller, optimized package. The full article delves deeper into technical details, including diagrams and further benchmarks. The code and a demo are available on GitHub.