English | 简体中文
A SIMD-accelerated drop-in replacement for Go's encoding/base64.
This package keeps the same public API and behavior as Go's standard encoding/base64, while using architecture-specific SIMD implementations where available.
- Compatible with
StdEncoding,URLEncoding,RawStdEncoding,RawURLEncoding,NewEncoding,WithPadding,Strict, stream encoder/decoder, and append helpers. - Uses runtime CPU feature detection on supported platforms.
- Falls back to the generic Go implementation when SIMD is unavailable or the input is too small for the optimized path.
| Architecture | SIMD path |
|---|---|
| AMD64 | SSE, AVX2, AVX512 VBMI |
| ARM64 | NEON |
| PPC64X | VSX / VMX (AltiVec) |
| S390X | Vector Facility |
| LOONG64 | LSX, LASX |
| RISCV64 | RVV |
The concrete path is selected automatically at runtime based on CPU features.
go get github.com/emmansun/base64Import this package instead of encoding/base64:
package main
import (
"fmt"
"github.com/emmansun/base64"
)
func main() {
src := []byte("hello, world")
enc := base64.StdEncoding.EncodeToString(src)
dec, err := base64.StdEncoding.DecodeString(enc)
if err != nil {
panic(err)
}
fmt.Println(enc)
fmt.Println(string(dec))
}Because the exported API follows the standard library, existing code usually only needs an import path change.
- Encoding and decoding semantics follow RFC 4648, matching Go's standard library behavior.
- Strict decoding is supported through
Encoding.Strict(). - Raw encodings without padding are supported through
RawStdEncoding,RawURLEncoding, orWithPadding(base64.NoPadding). - Inputs containing
\ror\nare handled the same way as the standard library, but decode throughput may not improve for newline-heavy data.
Performance depends on CPU model, microarchitecture, input size, encoding variant, and input shape. This repository does not publish a single benchmark table because numbers are hardware-dependent.
If performance matters for your workload, run benchmarks on your target machines.
- The package is tested in CI across the architectures covered by this repository.
- AMD64 AVX512 VBMI coverage is also validated with Intel SDE in CI.
Most of the generic Go implementation is derived from golang base64.
The amd64 implementation, especially the SSE path, and the arm64 SIMD implementation were inspired by aklomp/base64.