* Speeding Up zstd-rs Without Writing Code by Pairing Local and Web Gemini 4 Neon :properties: :export_file_name: generated/contents/blog/2026/c947fe :export_date: 2026-12-04 22:46 :export_updated: 2026-12-04 22:46 :export_lang: en :export_original: /blog/2026/587a92 :export_tags: rust webassembly performance ai-agent t3-code zstd-rs :end: I prepared a WebAssembly performance proposal for Shiguredo's Pure Rust Zstandard library [[https://github.com/shiguredo/zstd-rs][shiguredo/zstd-rs]]. Upstream merged those ideas into the [[https://github.com/shiguredo/zstd-rs/commit/2b5fd0b35ee8efe2326347b994b2e42b8a60cbf7][optimization commit]] and listed my name under [[https://github.com/shiguredo/zstd-rs#%E3%83%91%E3%83%95%E3%82%A9%E3%83%BC%E3%83%9E%E3%83%B3%E3%82%B9%E3%82%B3%E3%83%B3%E3%83%88%E3%83%AA%E3%83%93%E3%83%A5%E3%83%BC%E3%82%BF%E3%83%BC][Performance Contributors in the README]]. My own role stopped at linking local Gemini 4 Neon to a 10-agent Web Gemini 4 Neon swarm and issuing six short prompts to delegate verification to separate model families. I wrote zero lines of Rust. The companion post [[/blog/2026/c35660][Optimizing Pure Rust Zstd in WebAssembly to 89% of Emscripten Without Unsafe]] covers the data structures, loop splits, and ablations behind the speedup. From the maintainer side, voluntas wrote [[https://voluntas.ghost.io/rapid-zstd-rs/][zstd-rs に性能改善提案をいただいて約 2 倍早くなった]] (in Japanese), covering Shiguredo's benchmark setup and review process. [[github:shiguredo/zstd-rs::Rust][Zstandard (RFC 8878) Library]] ** Two posts that started the experiment Two posts on X kicked this off. In the first, voluntas at Shiguredo invited WebAssembly speed proposals for =zstd-rs= under strict rules: keep =#![forbid(unsafe_code)]=, =#![no_std]=, zero dependencies, and equal or better compression ratio on Chromium benchmarks. [[tweet:voluntas/2128689403686166705::America/Toronto::V][圧縮率を維持しつつ性能改善提案をしてくれる方を募集しています。unsafe 禁止 / no_std / 依存 0 / wasm (chromium)でのベンチマークという条件です。]] That same morning, Ryu posted a workflow that spawns 10 Gemini 4 Neon sub-agents in parallel inside the Gemini web app. Web Gemini draws from a separate quota from local Antigravity, so offloading exploration and design generation to the web while driving verification from local agents looked like a strong test case. [[tweet:_ryu15_/2128725141391876231::America/Toronto::Ryu][さて、web版Gemini 4 Neonはagyの使用量を全く使わない独自枠なので、サブエージェントNeon10体スウォームで最強エンジンを作ってもらいましょう! 現在すでにPrefill 4000tok/s Decode 140tok/sまで出るように! これがシンギュラリティ!]] ** Six prompts from start to finish The work spanned two threads, yet I typed six prompts in total. Agents handled code reading, WebAssembly builds, Chromium benchmarks, and test suites. [[./resources/public/img/c947fe-workflow.svg]] In the first thread, I pasted voluntas's post URL and told local Gemini 4 Neon: "Do this. Consult a Fable-class model and produce results worth reporting." My local environment runs inside [[https://t3.codes][T3 Code]], which lets Gemini 4 Neon delegate reviews and verification to Claude Fable 5.2 via Claude Code and GPT-6.2 Astra via Codex. Local Gemini 4 Neon measured the =shiguredo/zstd-rs= baseline, collected a V8 CPU profile, asked GPT-6.2 Astra to review the optimization plan, and ran six iterations with critical reviews from Claude Fable 5.2. Midway through, I opened a second thread and asked the agent to replicate Ryu's swarm setup by handing the current =zstd-rs= bottlenecks to Web Gemini 4 Neon. Once the 10-agent web swarm returned a 39 KB design document, I told the local side: "Checking this with Neon again adds little value, so launch a Fable-class model on the local side to bring a different perspective." Next, I asked: "Merge into this thread for maximum performance. You can settle the source thread." That combined both threads into one workspace. After the final patch passed benchmarks and tests, I asked: "Fork the repo and put it in a state the maintainer can merge. It is on GitHub, right?" The agent tried to open a pull request, saw that upstream disables pull requests, and reported back. I replied: "Put this PR body in a secret Gist viewable by link." I then posted the fork branch and Secret Gist URLs in the Shiguredo community Discord. ** Refuting the 10-agent web swarm with separate model families To run the web swarm, the local agent uploaded the source tree through the browser and triggered Task mode with 10 parallel sub-agents. Five agents focused on the encoder, while five audited the decoder and WebAssembly constraints, returning one consolidated design document. Letting the same model implement and review its own design lets blind spots pass unchecked. Instead, I had local Gemini 4 Neon launch Claude Fable 5.2 and GPT-6.2 Astra in turn as independent verifiers, measuring each idea one by one in interleaved Chromium =wasm-bench= runs. This cross-model check dropped several ideas that looked sound on paper yet regressed on real hardware. - Single-stream sequential Huffman decoding aimed to cut register spills, yet it broke CPU instruction-level parallelism and dropped decode speed from 427.7 MiB/s to 395.1 MiB/s, so we cut it. - Writing compressed blocks straight into the output buffer and pre-allocating scratch space disturbed the WebAssembly allocator layout and doubled standalone linear memory from 69.188 MiB to over 135.688 MiB, so we cut both. - Skipping long-distance 4-byte matches had zero effect because matches of length 6 or less accounted for 0.0% in the 7-byte hash path, so we cut it. Claude Fable 5.2 also caught a bug from an earlier iteration where =clamp= panicked on single-segment frames under 256 bytes, and fixed it. The same pass removed a 128 KiB zero-fill bug on small compressed blocks. Handing audits and measured ablations to different model families caught both speed regressions and panic bugs before I shared the proposal. ** Benchmark results and upstream integration The table below compares interleaved local Chromium runs of my [[https://github.com/conao3/zstd-rs/tree/feature/optimize-wasm-perf][fork branch commit 92aa3fc]] against baseline commit =3894aa1=. The test machine ran NixOS on an Intel Core i5-8400 with Chromium 158 and Rust 1.100.1 targeting =wasm32-unknown-unknown=, over six Silesia corpus files totaling 46,855,742 bytes. | Metric | Baseline 3894aa1 | Proposal 92aa3fc | Change | Emscripten Level 1 (same run) | |---+----+----+----+----| | Compression speed | 124.8 MiB/s | 190.4 MiB/s | +52.6% | 223.3 MiB/s | | Decompression speed | 279.4 MiB/s | 476.9 MiB/s | +70.7% | 537.1 MiB/s | | Compressed size | 15,764,178 B | 15,727,940 B | -36,238 B | 17,116,627 B | | Standalone wasm size | 93,642 B | 99,731 B | +6,089 B | - | | Standalone linear memory (post-decode) | 144.063 MiB | 69.188 MiB | -52.0% | 107.563 MiB | To check safety, GPT-6.2 Astra ran 87,228 mutated-frame differential tests and 1,747 post-error decoder reuse tests with zero output mismatches, zero error-kind mismatches, and zero panics. Compressed outputs matched byte for byte between native and WebAssembly across all six files, and all 95 tests, including =libzstd= interop tests, passed. Upstream =shiguredo/zstd-rs= disables external issues and pull requests and coordinates through Discord. I shared the proposal writeup as a Secret Gist alongside the fork branch URL in the Shiguredo community Discord. In that channel, cp-20 and serinuntius shared their own proposals from the same call, and voluntas combined ideas from all three while verifying with fuzzing. That fuzzing run uncovered an integer underflow bug still sitting in my proposal branch when a 2-byte sequence count produces =nb_sequences= of 0. Upstream resolved that bug with the fix cp-20 had built. Multiple contributors shared rough proposals through forks and Gists while the maintainer verified and merged the strongest parts. Those combined optimizations landed in upstream [[https://github.com/shiguredo/zstd-rs/commit/2b5fd0b35ee8efe2326347b994b2e42b8a60cbf7][commit 2b5fd0b35e]], and Shiguredo removed the README warning that =zstd-rs= took almost twice as long as the Emscripten build. Upstream GitHub Actions benchmarks report 201.7 MiB/s compression, 447.7 MiB/s decompression, and 63.375 MiB linear memory after aggregate decoding. Shiguredo also shipped this improvement in their browser storage engine [[https://github.com/shiguredo/ake][shiguredo/ake]]. ** Closing My work came down to stating constraints, widening ideas with the web swarm, and sending each candidate to separate model families for measured verification. The companion post [[/blog/2026/c35660][explaining the technical optimizations]] breaks down the exact data structures, loop splits, and rejected ablations in the proposal branch.