Repository navigation
feat(h2): compio H2 implementation - #775
johnnyshields wants to merge 12 commits into
Conversation
|
Wow, that's a huge PR. First of all, I would like to kindly, politely, and ask you with no offense: Is this work done by yourself manually, or partially/totally done with the help of LLM? Don't get me wrong - everyone uses copilot-like tools. Just want to make sure how did this huge work complete. And you're partially right on the comments of My basic attitude: if this project is not vibed, we welcome you join our organization, and maintain it separately (that is, opening a new repo in compio-rs, and work independently); if this project is vibed, you can still maintain and even publish it yourself, but be better with your own identifier on the prefix or suffix of the name. This PR is too large to review, I'm afraid. The final decision will be given after a discussion with all of our maintainers. The above is my own opinion. |
eacc973 to
c449fe2
Compare
|
@Berrysoft I did this with the help of Claude Code (Opus 4.6), but no, this project was not willy-nilly "one-shot vibed". You can read the code for yourself, this was several weeks of careful optimization, bench-marking, and fuzzing, conformance with 146 public specs, CVEs (plus ~100 others I didn't commit) and ~300+ unit tests. In the process I identified #771. It was 300+ commits including AI-assisted hardening passes after each one. AI assisted coding is clearly the future. Of course there are anti-patterns and "junk" ways of using AI, but there is also a way we can use it to produce high-quality, high-performance code. I believe this PR represents the latter, but please judge for yourself. I have GRPC mostly ready as well. |
|
Also, I should introduce myself properly. I am the CTO/Founder of TableCheck (~300 person company) based in Tokyo, Japan. I've been a coder for 20+ years, my first professional job was in algorithmic trading where we used C++, but I've built my own company mainly on Ruby. I'm now considering what high-throughput architectures can be used for new projects and found Compio in the process. I've also been working on a high-perf webserver (https://github.com/johnnyshields/mahalo) and a bunch of other things. |
…lds/compio into compio-h2-final-final
3f3cf1e to
5e3cd93
Compare
|
Hello, @johnnyshields . Sorry for this late reply, and unfortunately, the maintainers of
Anyway we thank your contribution, and will continue consider your suggestions on the performance of |
|
OK, it's no problem! I'll release it independently, as well as GRPC which will use it as a dependency. I did this work in my free time, not as part of my company, and it wouldn't make sense for TableCheck to sponsor Compio at this time. (But maybe in the future if we start actually using Compio in our stack!) If you change your mind in the future, please let me know! I'm happy to contribute this at any time. |
f89944f to
0866e61
Compare
|
@Berrysoft FYI I think this test run has surfaced a Windows ARM test hang in compio-net--it wouldn't be due to these changes. Raised here: #776 |
e7cc941 to
b02ddc4
Compare
|
We do appreciate all of your effort and interest in the project, and would love to work with you in future (I'm impressed by #771's results). However, as @Berrysoft explained, this PR is too large to merge into main compio repo. I'll close this for now, feel free to reply here or open an issue should you encounter any other problems. |
Summary
Add
compio-h2, a native HTTP/2 client and server implementation for compio. Theh2crate (hyperium/h2) andcompio-quicwere the primary references for protocol behavior and API design, but this is 100% original, ground-up written code — no source was copied or derived from any existing implementation.Benchmarks below--this is highly optimized and runs ~8x faster than tokio's hyperium/h2.
This is a precursor to releasing compio-grpc, which I also have WIP for. I will raise a PR for it after H2 is merged.
FYI this work depends upon #771 -- it will still run without it, but it will just be 3200x more slow.
How is it tested?
scripts/conformance) and also checked it against a number of other Go/Rust/Python sources such as CVE PoCs. Ultimately I ported everything to Rust tests cases (seetests/security.rs) and kept only h2spec, as it is the most thorough.benches/as well asscripts/conformance/h2load.sh.fuzz/-- this actually caught a few real bugs especially in the Huffman table.scripts/memleak/soak.sh, also the Asan work here: feat(ci): add asan memory leak test and suppression list #772. I also have separate work for Miri mem checking which I'll contribute as a separate PR and do it across all crates.Why a full new implementation?
I analyzed every existing Rust HTTP/2 implementation and found none with components we could use directly:
hyperium/h2 — The established Rust HTTP/2 implementation. Tightly coupled to tokio (
tokio::io::AsyncRead/AsyncWrite,tokio_util::codec). Its frame parsing and HPACK modules are internal (pub(crate)) and cannot be used independently. compio's completion-based I/O model (buffer ownership transfers to the kernel) is fundamentally incompatible with the readiness-based model (poll+ReadBuf) used by tokio and h2.h2-sans-io — A minimal, sans-I/O HTTP/2 frame codec targeting WASM and async-free environments. Covers basic frame parsing and flow control but does not provide stream state machines, connection management, or a full HPACK implementation.
fluke-hpack — A standalone HPACK crate forked from
hpack-rs. Lacks Huffman encoding, never-indexed/sensitivity support, header list size enforcement, and two-phase table size updates. compio-h2's custom HPACK module provides all of these with O(1) FNV hash lookups and abytes::Byteszero-copy pipeline.loona (formerly fluke) — A full HTTP/1+2 implementation built on io_uring with a custom buffer management layer. The most mature completion-based HTTP/2 implementation in Rust but is tightly coupled to its own I/O framework.
What's included
flow_controlled_lentracking for RFC 7540 §6.9.1 padding complianceRc<RefCell<ConnShared>>for thread-per-coreClientBuilderandServerBuilderwith fluent API for all HTTP/2 settingsSendRequesthandle withsend_request(),ready(), andshutdown()ResponseFuturefor awaiting response headersServerConnectionwithaccept(),shutdown(), andabrupt_shutdown()SendStreamwith data sending, trailer support, capacity reservation, and RST_STREAMRecvStreamwith cancel-safedata()andtrailers()methodsRecvFlowControlfor application-managed receive window updatesH2Errortype withreason(),is_io(),is_reset(),is_connection(),is_go_away(),is_remote(),is_library()helpersFrameErrorandHpackErrorfor granular error reportingtlsfeature gate withconnect/acceptwrappers, ALPNh2validation, andnative-tls/rustlssub-features forwarding tocompio-tlsBenchmarks
Run on Linux (WSL2), AMD Ryzen,
cargo bench -p compio-h2.HPACK codec
Huffman codec
Frame codec
RPC latency (compio-h2 vs tokio h2 crate)
Both sides configured with 1MB initial connection and stream windows. h2 crate uses multi-threaded tokio.
After zerocopy threshold fix: #771
compio-h2 achieves 6–9x lower latency than the h2 crate across all payload sizes, driven by the direct state machine access architecture (no channel overhead) and completion-based I/O.
Before zerocopy threshold fix: #771
io_uring
send_zerocopyrequires an extra CQE for buffer-release notification. For small writes, this triggered a ~40ms TCP delayed-ACK stall. The fix adds aZEROCOPY_THRESHOLD(8KB) in compio-net — writes below this size use regularsendinstead.*h2 crate numbers are different b/c I ran on a different machine
The 64KB result (88.6ms vs 27µs) shows the dramatic impact of the zerocopy stall — a 3,200x improvement after the fix.