Wait-Free Chunked I/O Buffer
We’re building a database and recently implemented a custom `I/O buffer` to handle the Postgres wire protocol. We considered `folly::IOBuf` and `absl::Cord`, but decided to implement a specialized version to avoid mutexes and simplify "late" size-prefixing.
**Key Technical Features:**
* **Chunked Storage:** Prevents large reallocations and minimizes `memcpy` by using a chain of fixed-size buffers.
* **Wait-Free:** Designed for high-concurrency network I/O without mutex contention.
* **Uncommitted Writes:** Allows reserving space at the start of a message for a size prefix that is only known after the payload is serialized, avoiding data shifts.
**Why custom?** Most generic "Cord" implementations were either slow or not truly concurrent. Our buffer allows one writer and one reader to work at the same time without locks and it actually works quite well to the benchmarks.
**Code & Details:**
* [Benchmarks & Blog Post](https://www.serenedb.com/blog/io-buffer)
* [Source Code (GitHub)](https://github.com/serenedb/serenedb/blob/main/libs/basics/message_buffer.h)
I'd love to hear your thoughts on our approach and if anyone has seen similar wins by moving away from `std::mutex` in their transport layers.
https://redd.it/1pu8cfs
@r_cpp
Post #24550
14