-
Notifications
You must be signed in to change notification settings - Fork 640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf(encoding): improve base64 encode/decode performance #6461
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6461 +/- ##
==========================================
- Coverage 95.87% 95.86% -0.01%
==========================================
Files 572 572
Lines 42831 42739 -92
Branches 6428 6419 -9
==========================================
- Hits 41065 40973 -92
Misses 1727 1727
Partials 39 39 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
const alphabet = new TextEncoder() | ||
.encode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"); | ||
const rAlphabet = new Uint8Array(128).fill(64); // alphabet.length | ||
alphabet.forEach((byte, i) => rAlphabet[byte] = i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like what BidirectionalMap
was created for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally had a Map for the rAlphabet variable but found it noticeably slower to index than a Uint8Array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Closes: #5944
This pull request brings the performance added in #6457 to the stable base64 and base64url functions, but in a non-breaking manner. The only difference a user would find is a difference in error message if providing an invalid encoded string.