跳到正文
DEV Community· ゴエンチョウ·· 13 天前AI 評分46

yolow64:從 PageSift 拆出的 Rust Base64 編解碼庫,速度超越同類實作

yolow64: a Base64 codec for Rust that outruns the incumbents — extracted from PageSift

AI 導讀

PageSift 內部使用的 Rust Base64 編解碼器 yolow64 已成為獨立的 MIT 授權程式庫。基準測試顯示,在 4 KiB–4 MiB 的嚴格模式下,其編碼和解碼速度約為 base64 crate 的 6.5–9 倍、base64-simd 的 1.7–2.5 倍;CRLF 容錯解碼則約快 4 倍。

正文

ゴエンチョウ

While building PageSift (a Rust web-content engine for LLM pipelines), I kept hitting Base64 in places where throughput and allocation control actually matter: browser screenshots, MCP resources, proxy authentication. The codec that grew inside PageSift is now its own MIT-licensed library: yolow64.

  • Runtime-dispatched SIMD: AVX2 (with an assembly bulk decode loop on Linux x86-64), NEON on AArch64, scalar fallback; runtime detection is cached.
  • Zero runtime dependencies, std only, Rust 1.89+.
  • Slice / append / owned-output APIs, validation without decoding, streaming decode, and a one-shot data-URL builder.
  • Whitespace-tolerant mode ignores exactly space/tab/CR/LF in a single pass — built for MIME-style input.

Measured on an i7-10700 (same process, three full runs, medians of seven-round medians; full method, charts and raw CSVs in the repo):

  • Strict mode at 4 KiB–4 MiB: ~6.5–9× faster than the base64 crate, ~1.7–2.5× faster than base64-simd, encode and decode.
  • CRLF-tolerant decode: ~4× faster than base64-simd's forgiving_decode at the same sizes.
  • On the same machine it runs level with moego, the fastest Go implementation I measured.
  • Honest footnote: at ≤128 B inputs the three libraries trade wins — those differences are nanoseconds and noise-sensitive, and the repo's tables print them as-is. The whitespace modes also don't accept exactly the same inputs across libraries; the comparison covers valid padded CRLF inputs.
[dependencies]
yolow64 = "0.1"

Repo: https://github.com/YOLOW92/yolow64 — benchmarks are reproducible from the included harness; corrections welcome.

來源:DEV Community · dev.to