Skip to content

feat(core): Use native btoa for envelope base64 encoding#6351

Merged
alwx merged 4 commits into
mainfrom
alwx/feature/base64-new
Jun 25, 2026
Merged

feat(core): Use native btoa for envelope base64 encoding#6351
alwx merged 4 commits into
mainfrom
alwx/feature/base64-new

Conversation

@alwx

@alwx alwx commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

Switch envelope base64 encoding on the RNSentry.captureEnvelope hot path from the bundled JS encoder to the runtime's native btoa. Hermes and modern JSC both expose btoa, and the native implementation should be significantly faster than the pure-JS encoder for the envelope payloads going through the bridge (profiles, attachments, replays).

The comes with no native code and no breaking changes for the customers.

💡 Motivation and Context

Closes #4884.
Alternative approach to #6314 (which should be closed now)

💚 How did you test it?

  • Added test/utils/base64.test.ts

📝 Checklist

  • I added tests to verify changes
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • All tests passing
  • No breaking changes

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Semver Impact of This PR

None (no version bump detected)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


  • feat(core): Use native btoa for envelope base64 encoding by alwx in #6351
  • feat(core): Use native btoa for envelope base64 encoding by alwx in #6351

🤖 This preview updates automatically when you update the PR.

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor
Fails
🚫 Pull request is not ready for merge, please add the "ready-to-merge" label to the pull request
🚫 Please consider adding a changelog entry for the next release.
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

### Features

- Use native btoa for envelope base64 encoding ([#6351](https://github.com/getsentry/sentry-react-native/pull/6351))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description or adding a skip-changelog label.

Generated by 🚫 dangerJS against 48a0f85

alwx added a commit that referenced this pull request Jun 25, 2026
@alwx alwx marked this pull request as ready for review June 25, 2026 11:28
@alwx

alwx commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 31680e8. Configure here.

@alwx alwx self-assigned this Jun 25, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Not sure if this is really testable but if it is it would be nice to test both the btoa available/unavailable cases

@antonis antonis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Added two nits but LGTM 🚀

Comment thread packages/core/src/js/utils/base64.ts Outdated

/**
* Encodes a byte array to base64. Uses the runtime's native `btoa` when
* available (Hermes and modern JSC both expose it), which is significantly

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: I think JSC does not always expose btoa

alwx added 4 commits June 25, 2026 16:06
Hermes and modern JSC both expose a native `btoa`, which is significantly
faster than the bundled JS encoder for the envelope payloads going through
`RNSentry.captureEnvelope`. Convert the envelope `Uint8Array` to a binary
string in 32KB chunks (to keep `String.fromCharCode.apply` argument count
below engine limits) and feed it to `btoa`. Falls back to the existing
`base64-js`-derived encoder when `btoa` is unavailable.

Closes #4884.
- Soften the JSDoc claim about JSC: not every JSC build exposes `btoa`,
  only some do.
- Add a test covering the JS-encoder fallback path by stashing
  `globalThis.btoa` so the module sees no native implementation.
@alwx alwx force-pushed the alwx/feature/base64-new branch from 9774389 to 48a0f85 Compare June 25, 2026 14:07
@alwx alwx merged commit ab203f9 into main Jun 25, 2026
58 of 65 checks passed
@alwx alwx deleted the alwx/feature/base64-new branch June 25, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use CPP Base64 Encoder for better performance (>10x)

2 participants