3 releases

0.1.2 Nov 26, 2023
0.1.1 Nov 13, 2023
0.1.0 Nov 3, 2023

#2999 in Parser implementations

Apache-2.0

575KB
443 lines

vb64

Fast, SIMD base64 codecs.

This crate implements base64 encoding and decoding as fast as possible. To get maximum performance, compile with -Ctarget-cpu=native and -Zbuild-std, which will ensure ideal instruction selection.

The following is a perf comparison with the base64 crate on a Zen 2 machine using AVX2 instructions; lower is better.

perf comparison with base64

On a Zen 2 machine and compiling with AVX2 support, decoding is between 2x to 2.5x faster than base64, while encoding is around 1.2x to 1.5x faster; with only SSSE3, decoding performance is even with base64 and encoding is much worse.

It is relatively unlikely that base64 decoding is such a massive bottleneck for your application that this matters, unless you're parsing base64 blobs embedded in JSON; you may want to consider using a binary format like Protobuf instead.

Also this crate uses std::simd so it requires nightly.

License: Apache-2.0


lib.rs:

Fast, SIMD base64 codecs.

This crate implements base64 encoding and decoding as fast as possible. To get maximum performance, compile with -Ctarget-cpu=native and -Zbuild-std, which will ensure ideal instruction selection.

The following is a perf comparison with the base64 crate on a Zen 2 machine using AVX2 instructions; lower is better.

![perf comparison with base64][graph-png]

On a Zen 2 machine and compiling with AVX2 support, decoding is between 2x to 2.5x faster than base64, while encoding is around 1.2x to 1.5x faster; with only SSSE3, decoding performance is even with base64 and encoding is much worse.

It is relatively unlikely that base64 decoding is such a massive bottleneck for your application that this matters, unless you're parsing base64 blobs embedded in JSON; you may want to consider using a binary format like Protobuf instead.

Also this crate uses std::simd so it requires nightly.

Constant time?? 👀

For decoding valid base64 (and for encoding any message), the implementations are essentially constant-time, but mostly by accident, since they are branchless and use shuffle-based lookup tables. Whether you want to believe that this decodes your private key .pem files without side-channel-leaking key material up to you (OpenSSL 100% leaks your private keys this way).

No runtime deps