How I made a Rust hot path 27x faster, and the AI fix I refused to merge A developer rebuilt the audio hot path of the open-source KeyEcho desktop app, achieving a 27x performance improvement by predecoding audio, deduplicating identical slices, implementing zero-copy playback, and removing a global mutex. The cached-lookup microbenchmark dropped from 1184.07 ns/op to 43.50 ns/op with zero sample bytes copied. The developer also refused to merge an AI agent's suggested change that would have quietly broken a feature. Two years ago I open-sourced KeyEcho, a small desktop app that plays a mechanical-keyboard sound the instant you press a key. It got 800+ stars. Then I shipped v0.0.5 in July 2024 and went quiet. The issues never stopped. People asked for sound packs, reported platform bugs, and kept using a thing I had stopped maintaining. This month I came back and shipped 1.0 in a single PR: 130 files, 11,405 lines added and 9,292 removed. The core of it was a rebuild of the audio hot path. The cached-lookup microbenchmark went from 1184.07 ns/op with 66.84 KiB copied per key to 43.50 ns/op with zero sample bytes copied. That is 27x on the average slice and 38x on the largest. I built it with an AI agent writing a lot of the code. This post is how the rework works, why Rust made that safe to do fast, and the one change the agent suggested that looked clean and would have quietly broken a feature. KeyEcho's latency-sensitive path is short. A global keyboard hook fires on every key event. The first key-down of each press is pushed into a bounded queue. An audio thread pulls from the queue, maps the key to a slice of the selected sound pack, and plays it locally. Because the path is short, anything left inside it is paid on every keystroke: any decode work, any allocation, any sample copy, any lock. The whole game is getting those out of the per-key path. Credit where it is due. v0.0.5 was a light, quick thing: Tauri + Rust, small builds, low memory; native keyboard listening I wrote by hand against each platform's API, with almost no unsafe; lossless WAV audio with no decompression step; and it already cached decoded audio in an LRU, so hitting the same key twice did not decode twice. It ran for two years and a few hundred people used it. It was not slow software. But "already fast" and "no headroom left" are two different things. Even on a cache hit, each key press still copied the samples 66.84 KiB in the benchmark and went through a global mutex shared with pack switching and volume changes. A cache miss still decoded on the spot. What 1.0 removed is exactly those: that copy, that lock, and the fact that cache misses happen at all. The rebuild came down to four moves. Predecode once, when a pack is selected. A sound pack is a folder with a sound.ogg and a config.json . The config maps each key to a slice of the audio: key - start ms, duration ms . When you select a pack, every slice is decoded up front, one time. Nothing decodes during a keystroke. Deduplicate identical slices. Many keys point at the same slice, so decoding per key would decode the same audio many times. The builder keys a map on the start ms, duration ms pair, decodes each unique slice once, and shares it: js // Decode each unique slice once; identical slices share one buffer. let mut slice sources: HashMap< u64; 2 , AudioSource = HashMap::new ; let mut key sources: HashMap