You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use CPP Base64 Encoder for better performance (>10x) #4884
Solution could be also try to avoid the base64 encoding of the envelopes (maybe pass it as an object to the native layers, or as an array (note that we have ran into issue in the past with the array size (link TBA)))
There is also function utf8ToBytes that is very slow. This function could possibly use native TextEncoder which should speed it up significantly. Here is implementation I used (10x - 15x faster than JS implementation):
/** * Converts a UTF-8 string to an array of bytes using native TextEncoder. * This function is intended as a more performant alternative to the * utf8ToBytes function found in some Buffer polyfills. * * @param {string} string The string to convert. * @param {number} [unitsInput] Optional. Similar to the 'units' in the polyfill's * utf8ToBytes, this aims to limit the number of bytes. * If 0, undefined, null, or NaN, it's treated as Infinity * (no limit), mimicking the polyfill's `|| Infinity` behavior. * Otherwise, the output byte array will be truncated to this length. * @returns {number[]} An array of numbers, where each number represents a byte. */exportfunctionutf8ToBytes(string,unitsInput){letunits;// Mimic the polyfill's `units = units || Infinity` behavior for common falsy values// that would lead to `Infinity` in the original.if(unitsInput===undefined||unitsInput===null||unitsInput===0||// Original `|| Infinity` makes 0 effectively Infinity(typeofunitsInput==='number'&&Number.isNaN(unitsInput))){units=Infinity;}else{units=Number(unitsInput);// Coerce to number (e.g., if it was a string "10")if(Number.isNaN(units)){// If coercion results in NaN (e.g., from "abc")units=Infinity;}}constencoder=newTextEncoder();// UTF-8 by defaultconstuint8Array=encoder.encode(string);letfinalUint8Array;if(units<0){// If units was specified as a negative number not caught by the Infinity conditions.// The polyfill would also likely break immediately or produce no bytes.finalUint8Array=newUint8Array(0);}elseif(units!==Infinity&&uint8Array.length>units){// Truncate if the encoded length is greater than the specified units.// Ensure units is not negative for slice, though above logic should handle most.finalUint8Array=uint8Array.slice(0,Math.max(0,units));}else{// No truncation needed or units is InfinityfinalUint8Array=uint8Array;}returnfinalUint8Array;}
Activity
Nodonisko commentedon Jun 4, 2025
There is also function
utf8ToBytesthat is very slow. This function could possibly use nativeTextEncoderwhich should speed it up significantly. Here is implementation I used (10x - 15x faster than JS implementation):huuphat1908 commentedon Oct 7, 2025
Totally agree.
utf8ToBytesis too slowfeat(core): Use react-native-quick-base64 for envelope encoding when …
feat(core): Use react-native-quick-base64 for envelope encoding when …
feat(core): Use native btoa for envelope base64 encoding
feat(core): Use native btoa for envelope base64 encoding (getsentry#6351
github-actions commentedon Jul 2, 2026
A PR closing this issue has just been released 🚀
This issue was referenced by PR #6351, which was included in the 8.17.0 release.