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

Resumable host calls #26

Open
jedisct1 opened this issue Apr 15, 2020 · 3 comments
Open

Resumable host calls #26

jedisct1 opened this issue Apr 15, 2020 · 3 comments

Comments

@jedisct1
Copy link
Member

Some functions, such as password stretching functions and key pair creation functions, can take a long time to return.

This is an issue in contexts that don't expect calls to be blocking. JavaScript is an obvious example of this.

The usual way to workaround it is to make the API asynchronous (as in scrypt-async). A computation step is performed, then the function returns but signals that more steps are needed in order to complete.

We can do something very similar. Reserve an error code for this, and bindings would try again until the operation returns a different error code.

Is there a better way to address this? I remember discussions about having the equivalent of promises in WASI. Is it still something being considered, and that we could use instead?

jedisct1 added a commit to jedisct1/wasi-crypto-preview that referenced this issue Apr 15, 2020
@tniessen
Copy link
Member

tniessen commented May 8, 2020

This is a fundamental problem with WebAssembly. Most JavaScript applications only use WebAssembly in a background thread for this very reason. For standalone WebAssembly applications, threading will eventually be necessary to be able to compete with the performance of native applications.

@jedisct1
Copy link
Member Author

jedisct1 commented May 8, 2020

I couldn't agree more, threading will be absolutely necessary.

But what should we do now?

Should we assume that all runtimes are going to have support for threads in a very near future?

That would makes things a little be easier, but is it a reasonable assertion?

What do you think?

@tniessen
Copy link
Member

Sorry @jedisct1. I really appreciate being involved in this, but I have barely had time to work through hundreds and hundreds of GitHub notifications from other projects for the last few months.

I think asynchronous behavior adds an incredible amount of complexity, and security aspects. That would require a background thread pool, which would somehow have to work together with explicit WebAssembly threads. (For example, WebAssembly in a browser should probably not be allowed to use 8 threads + 8 parallel asynchronous operations, which could easily use all available CPU resources.)

Asynchronous is what WebCrypto does, and it has its benefits for such a high-level environment (JavaScript in a browser). Node.js already has a thread pool and therefore also allows off-loading some crypto work to the thread pool. However, as long as WebAssembly does not have a unified concept of asynchronous background work (which will probably never be the case due to its low-level nature), I don't think we should add that complexity here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants