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

Remove unnecessary conversions to hex format #643

Merged
merged 1 commit into from
Dec 6, 2023

Conversation

frankhinek
Copy link
Contributor

@frankhinek frankhinek commented Dec 5, 2023

Summary

This PR primarily focuses on performance improvement for the two digital signature algorithms supported by `dwn-sdk-js.

Context

In this Discord thread @shamilovtim noted significant delays while profiling web5-wallet performance.

During the troubleshooting process, a tangentially related issue was discovered that unnecessarily reduces the performance of Ed25519 and secp256k1 sign operations. While updating dwn-sdk-js to the v2.0 versions of @noble/ed5519 and @noble/secp256k1 in PR #396, unnecessary conversions to hex format were added in the sign() method (but not verify()).

The result of this change is that sign() performance degrades rapidly as the data size of the content increases:

Screenshot 2023-12-05 at 12 29 40 PM

With a 100MB data payload, the sign operation in dwn-sdk-js is ⚠️ 40 times slower ⚠️ than it should be.

If we switch the time axis to log scale, you can see that the verify operations both in dwn-sdk-js and @noble/ed25519 track almost identically, since verify does not include the conversion to hex before verification.

Screenshot 2023-12-05 at 12 30 35 PM

Changes

  • Remove all occurrences of hex format conversions from both:
    • src/jose/algorithms/signing/ed25519.ts
    • src/utils/secp256k1.ts

After implementing these changes, the performance of the sign operation is nearly identical whether called from the dwn-sdk-js wrapper or directly to the @noble lib and scales linearly as the payload size increases:

Screenshot 2023-12-05 at 12 49 27 PM

@frankhinek frankhinek added the performance performance improvement label Dec 5, 2023
@frankhinek frankhinek self-assigned this Dec 5, 2023
Copy link

codesandbox bot commented Dec 5, 2023

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@frankhinek
Copy link
Contributor Author

Another +1 for migrating dwn-sdk-js to use the @web5/crypto libs 😃

Copy link
Contributor

@thehenrytsai thehenrytsai left a comment

Choose a reason for hiding this comment

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

This is great! Thanks!

@thehenrytsai thehenrytsai merged commit b8901e9 into main Dec 6, 2023
4 checks passed
@thehenrytsai thehenrytsai deleted the frankhinek/remove-crypto-hex-conversion branch December 6, 2023 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance performance improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants