-
-
Notifications
You must be signed in to change notification settings - Fork 65
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
increase base64 performance in browser using FileReader.readAsDataURL() #50
Comments
Hi @benatkin, Can you show some kind of benchmarks that readAsDataURL outperforms the current approach? In any case, the current implementation is fast enough as operations on typed arrays are quickly optimized by JavaScript runtimes. They perform almost as well as C code. |
Sorry for the delayed update. I did one with Deno bench. I probably need to make it vary the arrays, but I don't think it would cache the answers. It says the FileReader one is quite a bit faster:
|
This was converting to base64, I omitted converting from base64 - I agree it doesn't seem like it should be faster since it's a native code to native code comparison. I think the string concatenation still slows code down though, and that is used in converting to base64. |
Is your feature request related to a problem? Please describe.
When using an isometric library I prefer them to use functionality from the platform where possible. This uses fromCharCode to convert from binary to base64 when FileReader.readAsDataURL() ought to work.
Describe the solution you'd like
Wrapping FileReader.readAsDataURL would be preferable, because instead of looping through each byte in JS, a native method does the whole thing.
https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsDataURL
Describe alternatives you've considered
I considered using platform functionality everywhere if it would work, however, FileReader.readAsDataURL is not available on Node. Uint8Array is on Node. So they still need separate ways to work.
Additional context
buffer.toBase64
is used in y-webrtc I was thinking of using it for saving Y Docs to localStorage but may end up using IndexedDB. My code already uses localStorage and IndexedDB isn't supported on Firefox Private Browsing sessions so that's why I may keep using localStorage for the time being.The text was updated successfully, but these errors were encountered: