square / okio

A modern I/O library for Android, Java, and Kotlin Multiplatform.
https://square.github.io/okio/
Apache License 2.0
8.81k stars 1.18k forks source link

Slow Sha512 Performance on JS #1206

Open luca992 opened 1 year ago

luca992 commented 1 year ago

Sha512 performance is very slow on JS due to it using Long numbers.

JS does not have 64-bit integers, so Kotlin/JS has to emulate them. Which causes so much overhead on JS that when I run Sha512 on my web app it causes my entire web app to freeze for a few seconds:

Screenshot 2023-01-16 at 8 16 28 PM

If possible, could Sha512 be ported to use Double for the JS target? Which are much much faster

swankjesse commented 1 year ago

Oooooh yeah that’s not great. We should look at JS-language implementations of SHA256 and see what types they’re using.

Lisi-Chen commented 1 year ago

Hi @luca992 and @swankjesse,

I've observed the performance challenges with Sha512 in JS, particularly around the emulation of 64-bit integers. I'm keen to dive deeper and work on alternatives like leveraging Double for the JS target or referencing best practices from existing JS SHA256 implementations.

Could I be assigned to this issue?

Thanks, Lisi

swankjesse commented 1 year ago

We’re not actively seeking new contributors to this project at the moment. If you’d like to offer advice or code, please do! But I don’t want to promisee that we’re going to accept your work when you’re done.