-
Notifications
You must be signed in to change notification settings - Fork 447
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
refactor!: remove unnecessary async from crypto methods #1963
Conversation
7b702b9
to
84d2082
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dd77b85
to
2fd3ebb
Compare
The create function is already made sync. I chose to keep the encrypt function returning a promise because that is what the browser equivalent does. Can change if it's fine to do this. The other places where the require-await comments were removed still return promises. With current linter rules any function returning a promise must be an async function. |
My apologies, I had actually intended to link to create function in HMAC
My understanding is that given they run in different environments that should be inconsequential, but @achingbrain can comment further.
The premise was that given the functions are not doing asynchronous work, they should not return a promise. So they need to be refactored to not create promises. |
There may be some situations where the function being returned could be refactored to not return a promise. I will check for this. |
I've made the hmac create function synchronous. I looked at whether some of the keys methods can be made synchronous and they can, although mainly just for nodejs. Ed25519 can be made synchronous in both the browser and nodejs. |
Ah, hmac's create function for the browser cannot be made sync. Did you talk with @achingbrain yet about if they have to match? Seems like they should, especially if part of public API. |
I think would be best for the node/browser mirror methods to keep parity wrt their interfaces. One returning a value while the other returns a Promise looks like trouble. There are cases (Ed25519 keys) where both node and browser methods could be synchronous. Since this is not a public API/not exported from package and gets turned into a promise via the public API methods, changing these seems ok. |
i did some benchmarking with synchronous ed25519 in node and the async api is much faster. |
Could you share the benchmark results here, I find it strange that's the case. |
https://gist.github.com/tabcat/871bca3b48fb23c30ab3ba4dc243b8fa i fixed the benchmarks and the results are:
I made a mistake with how concurrency is handled in the benchmark |
8e43418
to
77b96a2
Compare
I've made the ed25519 methods all synchronous, this doesn't change public api since they are later wrapped in a promise inside of keys/index.ts use the refactor semantic commit tag but maybe chore would be better? |
Thanks! |
Removed async keyword from function which don't: 1) do any async work 2) return a promise 3) have an async browser equivalent Closes: libp2p#1949 --------- Co-authored-by: Chad Nehemiah <[email protected]> Co-authored-by: achingbrain <[email protected]>
Removed async keyword from function which don't:
Closes: #1949