arXiv:2610.17406cs.DSOct 2026

Manuscript Offprint

arXiv:2610.17406

Fast Forgiving Base64 Decoding with SIMD Instructions

Daniel Lemire

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

DANIEL LEMIRE, Université du Québec (TELUQ), Canada

On the Internet, we use the Base64 format to represent binary data (e.g., images or cryptographic keys) as text. The ES2026 JavaScript standard, following the WHATWG forgiving-base64 rules, requires decoders to ignore ASCII whitespace while rejecting other non-alphabet characters. Prior SIMD Base64 decoders assume whitespace-free input. We present a block-oriented decoding algorithm that removes whitespace inside the SIMD loop: clean 64-character blocks are decoded directly, while blocks with ignorable characters are compacted into a small stack buffer. We provide implementations for x64 (SSSE3 through AVX-512 VBMI2), ARM NEON, and LoongArch. Our C++ decoder reaches up to 94 GB s −1^{-1} on recent AMD Zen 5 processors. In Node.js 25, integration of our decoder raises Uint8Array.fromBase64 throughput by up to 6× compared with Node.js 19. The implementation has been adopted by major browsers and JavaScript runtimes.

CCS Concepts: • Computing methodologies → Vector / streaming algorithms; • Information systems → Browsers.

Additional Key Words and Phrases: Base64 decoding, browser performance, SIMD acceleration, JavaScript optimization, high-throughput decoding

1 Introduction

Base64 is a binary-to-text encoding scheme that converts arbitrary binary data—images, files, any sequence of bytes—into a safe, printable ASCII string using a 64-character alphabet (A–Z, a–z, 0–9, +, /). We use it to send binary data by email [6] and inside JSON, HTML and XML documents.

Most general-purpose processors (x64, ARM, etc.) support single-instruction-multiple-data (SIMD) instructions [5]. Instead of operating on single words, SIMD instructions operate on several words at once. For example, you may add a vector of 16 words to another vector of 16 words using one instruction. Muła and Lemire [14, 15] showed that—with SIMD instructions—we can encode and decode Base64 content at gigabytes per second: we may load 32 characters at once and produce 24 bytes using a handful of instructions. Several libraries build on this work, among them aklomp/base64 [9] and Turbo-Base64 [18]; we survey them in Section 3. They assume regular input: every byte is a Base64 character (or padding), with no whitespace or other special characters. Under that assumption the input can be loaded and decoded uniformly—each register-sized block of characters becomes a fixed number of output bytes, with no data-dependent control flow—which fits SIMD execution naturally.

That assumption does not hold on the web. Cryptographic keys and email attachments are stored in fixed-width lines separated by line feeds ('\n'), and the WHATWG forgiving-base64 rules [22] require a decoder to ignore ASCII whitespace while rejecting every other character outside the alphabet. Decoding is harder than encoding: any binary content is valid input to an encoder, but a decoder must validate the input and skip a sparse, irregularly placed subset of it.

Character by character, ignoring some characters is no concern: a branch per character suffices. But when characters are loaded in blocks we must detect and remove the ignorable ones from each newly loaded block. Pruning them in a separate pass before decoding is possible, but Muła and Lemire report that such pruning can cost as much as the decoding itself [14]. We find that a vectorized whitespace-removal pass in front of a fast clean-input decoder is usually slower than a decoder that does both at once. No SIMD Base64 decoder we know of removes ignorable characters inside its main loop; the base64-simd [17] library implements the same forgiving rules, but as a strip-then-decode pipeline.

Author's Contact Information: Daniel Lemire, daniel.lemire@teluq.ca, Université du Québec (TELUQ), Montreal, Quebec, Canada.

Daniel Lemire

Table 1. Base64 mapping between 6-bit values and ASCII characters. The standard alphabet uses + and / for the last two characters while the URL variant uses - and _.

valuecharvaluecharvaluecharvaluecharvaluecharvaluechar
0A1B2C3D4E5F
6G7H8I9J10K11L
12M13N14O15P16Q17R
18S19T20U21V22W23X
24Y25Z26a27b28c29d
30e31f32g33h34i35j
36k37l38m39n40o41p
42q43r44s45t46u47v
48w49x50y51z52θ531
542553564575586597
60861962+ or -63/ or _

The JavaScript Interface. These conventions are now part of a standard library API. JavaScript has a built-in type for arrays of 8-bit integers called Uint8Array. The JavaScript standard ECMAScript 2026 (ES2026) added Uint8Array.fromBase64 and Uint8Array.toBase64, following the forgiving-base64 rules. They are supported by all major browsers (WebKit-based, Chromium-based, Firefox and more) and by major JavaScript runtimes (Node.js, Deno, Bun). Encoding maps three bytes (24 bits) to four 6-bit values, each taken from the alphabet in Table 1. Because ‘+’ and ‘/’ have special meanings in URLs [16], a URL variant uses ‘-’ and ‘_’ instead. Decoding is the reverse. ASCII whitespace in the input is ignored [13]. When the binary data is not divisible by three, we encode a single byte into two Base64 characters or two bytes into three, and we may add one or two padding characters ('=') so that the length is divisible by four.

Design Space. We might assume there are no ignorable characters and fall back on a slower approach once one is encountered. Unfortunately, a single whitespace character early in the input would then ruin the whole decode. A more nuanced approach falls back only locally, on the blocks where whitespace occurs. That is closer to workable, but two difficulties remain:

  • It scales poorly to wide registers. Recent processors have 64-byte SIMD registers, and we would like to work in units of 64 characters. Yet with line endings every 72 characters, most 64-character blocks contain whitespace, so the “local” fallback is the common case.

  • Because four characters decode to three bytes, we cannot start decoding at an arbitrary offset. After removing whitespace, a 64-character block no longer holds a whole number of decodable groups, and completing the last one requires characters from the following block.

Thus, we developed the following strategy. We load the Base64 input in fixed-size blocks of 64 characters. We scan each block for errors and ignorable characters with SIMD instructions. When a block contains no ignorable character—and nothing is pending from an earlier block—we decode it directly to the output. When ignorable characters are found, we write the block’s alphabet characters to a buffer on the stack, omitting the ignorable ones. Whenever the stack buffer approaches its capacity, we decode all of its complete 64-character groups to the output and slide the remainder to the front. The stack buffer absorbs the misalignment that whitespace removal introduces, while the decoding step itself always sees uniform 64-character groups.

Our contributions are: (1) a block-oriented Base64 decoding algorithm that enforces WHATWG/ES2026 forgiving-base64 semantics—ignoring ASCII whitespace while reporting invalid characters—and does the whitespace removal inside the decoding loop rather than as a separate pass; (2) compaction and decoding kernels for x64 (SSSE3, AVX2, AVX-512 VBMI2), ARM NEON, and LoongArch LSX/LASX, including runtime instruction-set dispatch and specialized handling of single-whitespace blocks, together with a discussion of how the design maps onto SVE2 and RVV (Section 5.4); (3) an empirical study across ISAs, datasets, and whitespace densities that compares against the fastest available SIMD Base64 libraries (Section 6.7), reports hardware performance counters, decomposes the decoding time (Section 6.8), and ablates the main design parameters; and (4) an open-source implementation integrated into major browsers and JavaScript runtimes.