How fast can browsers process base64 data?

https://news.ycombinator.com/rss Hits: 6
Summary

Base64 is a binary-to-text encoding scheme that converts arbitrary binary data (like images, files, or any sequence of bytes) into a safe, printable ASCII string using a 64-character alphabet (A–Z, a–z, 0–9, +, /). Browsers use it in JavaScript to embedding binary data directly in code or HTML or to transmitting binary data as text. Browsers recently added convenient and safe functions to process base 64 functions Uint8Array.toBase64() and Uint8Array.fromBase64(). Though they are several parameters, it comes down to an encoding and a decoding function. const b64 = Base64.toBase64(bytes); // string const recovered = Base64.fromBase64(b64); // Uint8Array When encoding, it takes 24 bits from the input. These 24 bits are divided into four 6-bit segments, and each 6-bit value (ranging from 0 to 63) is mapped to a specific character from the Base64 alphabet: the first 26 characters are uppercase letters A-Z, the next 26 are lowercase a-z, then digits 0-9, followed by + and / as the 62nd and 63rd characters. The equals sign = is used as padding when the input length is not a multiple of 3 bytes. How fast can they be ? Suppose that you consumed 3 bytes and produced 4 bytes per CPU cycle. At 4.5 GHz, it would be that you would encode to base64 at 13.5 GB/s. We expect lower performance going in the other direction. When encoding, any input is valid: any binary data will do. However, when decoding, we must handle errors and skip spaces. I wrote an in-browser benchmark. You can try it out in your favorite browser. I decided to try it out on my Apple M4 processor, to see how fast the various browsers are. I use blocks of 64 kiB. The speed is measured with respect to the binary data. browser encoding speed decoding speed Safari 17 GB/s 9.4 GB/s SigmaOS 17 GB/s 9.4 GB/s Chrome 19 GB/s 4.6 GB/s Edge 19 GB/s 4.6 GB/s Brave 19 GB/s 4.6 GB/s Servo 0.34 GB/s 0.40 GB/s Firefox 0.34 GB/s 0.40 GB/s Safari seems to have slightly slower encoding speed than the Chromium browsers (Chome, Edge...

First seen: 2025-12-06 00:18

Last seen: 2025-12-06 06:18