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

atob and btoa are slower than node #13838

Closed
ry opened this issue Mar 4, 2022 · 2 comments
Closed

atob and btoa are slower than node #13838

ry opened this issue Mar 4, 2022 · 2 comments
Labels
perf performance related

Comments

@ry
Copy link
Member

ry commented Mar 4, 2022

https://twitter.com/jarredsumner/status/1499715417773789185

@ry ry added the perf performance related label Mar 4, 2022
@aapoalas
Copy link
Collaborator

aapoalas commented Mar 4, 2022

Would it be best to have the op_base64_decode and _encode do all the work on Rust side?

ie.
op_base64_decode would return a String so that JS side doesn't have to do all the Uint8Array to Array to string mapping and joining.

op_base64_encode would take a String, check it for invalid characters and return an error if necessary (can ops directly return-throw a DomException? I see a lot of DomExceptionSomething in Rust code so I presume it's okay), convert to u8 slice and pass to base64::encode_config?

@AaronO
Copy link
Contributor

AaronO commented Mar 7, 2022

Deno (main) now outperforms Node following PRs I've landed since Friday.
We're over 4x faster on long strings, ~10% faster on short strings.

Node

❯ node -v; node ./cli/bench/deno_common.js
v17.6.0
b64_rt_long:         	n = 100, dt = 2.755s, r = 36/s, t = 27549999ns/op
b64_rt_short:        	n = 1000000, dt = 0.507s, r = 1972387/s, t = 507ns/op

Deno (main 788553b)

❯ ./target/release/deno run --unstable -A ./cli/bench/deno_common.js
b64_rt_long:         	n = 100, dt = 0.626s, r = 160/s, t = 6260000ns/op
b64_rt_short:        	n = 1000000, dt = 0.451s, r = 2217295/s, t = 451ns/op

Conclusions

I would consider this fixed for now. There are further improvements in upcoming deno PRs, I've also submitted 2 PRs upstream to rust-base64: marshallpierce/rust-base64#180 and marshallpierce/rust-base64#179

@AaronO AaronO closed this as completed Mar 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf performance related
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants