8000 perf(encoding): improve base64 encode/decode performance by BlackAsLight · Pull Request #6461 · denoland/std · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
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

Merged
merged 1 commit into from
Mar 10, 2025

Conversation

BlackAsLight
Copy link
Contributor

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.

@BlackAsLight BlackAsLight requested a review from kt3k as a code owner March 4, 2025 10:15
Copy link
codecov bot commented Mar 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.86%. Comparing base (fc167d6) to head (017a504).
Report is 11 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment on lines +31 to +34
const alphabet = new TextEncoder()
.encode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
const rAlphabet = new Uint8Array(128).fill(64); // alphabet.length
alphabet.forEach((byte, i) => rAlphabet[byte] = i);
Copy link
Contributor
@iuioiua iuioiua Mar 7, 2025

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.

Copy link
Contributor Author

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

@kt3k kt3k changed the title perf(encoding): brought to stable base64 functions perf(encoding): improve base64 encode/decode performance Mar 10, 2025
Copy link
Member
@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kt3k kt3k merged commit d6823ad into denoland:main Mar 10, 2025
19 checks passed
@BlackAsLight BlackAsLight deleted the encoding_stable_base64 branch March 10, 2025 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

encodeBase64/decodeBase64 seems to be inefficient
3 participants
0