Rewrote my C++ Zsh history daemon to kill OS overhead. Real world typing latency is ~7ms for 500k commands.

Hey folks,

I posted a few days ago about a Zsh history middleware I've been building called BSH. Just to clarify up front: BSH is strictly a passion project to see how low I can push keystroke latency using a local-only C++ daemon. (I include tools like Atuin and FZF in my benchmarks purely because they are standard baselines everyone knows, but BSH has a much narrower focus).

If you are a latency nerd, you might find this fun.

The Benchmarks (and a correction) In my last post, I mentioned hitting 2.5ms for 500k commands. I have to admit that previous benchmark was way too forgiving. I completely rewrote the test suite to use highly-variable, realistic shell data and to measure the exact execution path the tools actually take in real life (including the full Zsh socket round-trip overhead).

That real-world testing added a bit of time to the results, but because of the architectural improvements below, the scaling remains incredibly flat:

  • 10k commands: BSH 4.21ms | FZF 9.44ms | Atuin 14.78ms | Grep 9.37ms
  • 100k commands: BSH 5.61ms | Atuin 16.08ms | FZF 39.21ms | Grep 77.96ms
  • 500k commands: BSH 7.38ms | Atuin 22.37ms | FZF 200.61ms | Grep 417.62m

What changed since last week to get here: I ended up completely rewriting the architecture to kill OS and I/O overhead.

  • I ripped out the ephemeral client binary. Now, Zsh talks directly to the C++ daemon via native Unix sockets (zmodload zsh/net/socket).
  • Async I/O & Git: Database writes and libgit2 branch resolution are now pushed to a dedicated background thread with an in-memory LRU cache. Your keystrokes never wait on disk syncs or filesystem traversal.
  • All SQLite FTS5 queries are precompiled into memory at daemon startup.
  • All the string math, box-drawing, and truncation is handled asynchronously in C++, so the Zsh interpreter does zero heavy lifting.

TL;DR of Features It acts a bit like IntelliSense for your terminal. You can filter suggestions by your current Directory or Git Branch, and toggle a filter (Ctrl+F) to instantly hide commands that exited with errors (like typos or bad compiles). Everything stays 100% local.

Try it out I finally got it packaged so you don't have to build from source:

  • macOS: brew tap karthikeyjoshi/bsh && brew install bsh
  • Arch: yay -S aur/bsh

(There is also a universal install script, but I'm omitting it here because Reddit's spam filters hate curl | bash links!)

Repo: https://github.com/joshikarthikey/bsh

If you know C++, CMake, Zsh internals, or just want to roast my architecture, PRs and issues are highly welcome. I'd love to hack on this with some like-minded people.

Posted Feb 26, 2026, 3:25 AM UTC

10
Loading comments…