perf(codec): replace base64 codec with simdutf SIMD-accelerated implementation#54
Merged
Conversation
…mentation
Replaces the René Nyffenegger header-only base64.h with simdutf v8.2.0,
the same SIMD-accelerated codec used internally by Node.js, Bun, and
Deno. Vendored as the upstream amalgamation (cpp/simdutf.{h,cpp})
keeping the zero-external-dependency setup.
- Encode (base64FromArrayBuffer) calls simdutf::binary_to_base64
directly into a pre-sized output buffer, with no intermediate
std::string copy.
- Decode (base64ToArrayBuffer) mirrors V8's Uint8Array.fromBase64
via simdutf::base64_to_binary_safe with last_chunk_handling::loose
and decode_up_to_bad_char=true. The decoded std::string is moved
into a DecodedBuffer (jsi::MutableBuffer) and returned as
jsi::ArrayBuffer(rt, shared_ptr<...>) — no memcpy.
Roundtrip throughput now matches Hermes' built-in atob/btoa on the
example app's image.json benchmark.
Behaviour changes (TC39-compliant, see Uint8Array.fromBase64 spec):
- Mid-stream padding (e.g. 'SQ==QU0=') now throws instead of
silently decoding the prefix.
- Embedded '\n' without removeLinebreaks=true now throws instead
of being silently ignored.
Test fixtures in example/src/tests/{corrupt,linebreaks}.ts updated
accordingly.
Adapted from #50, ported onto the post-codegen QuickBase64Impl.cpp
and combined with the MutableBuffer-based no-memcpy decode path.
Closes #50
Co-authored-by: Karol Binkowski <karolbinkowski3@proton.me>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #50
Benchmark
Before
After
It's now roughly 2~3x faster, and it performs as fast as Hermes' built-in
atob&btoafunctions (string only).Thanks @GrzywN!