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

What about replacing Asyncify with Atomics and SharedArrayBuffer? #35

Closed
rhashimoto opened this issue Jan 20, 2022 · 3 comments
Closed

What about replacing Asyncify with Atomics and SharedArrayBuffer? #35

rhashimoto opened this issue Jan 20, 2022 · 3 comments
Labels
faq

Comments

@rhashimoto
Copy link
Owner

@rhashimoto rhashimoto commented Jan 20, 2022

There are significant time and space penalties for using WebAssembly SQLite built with Asyncify, which allows SQLite to callback to asynchronous Javascript functions. This is why wa-sqlite provides both synchronous (without Asyncify) and asynchronous builds, so developers can avoid those penalties if they don't need to use asynchronous callbacks.

Asynchronous callbacks are especially useful for calling asynchronous APIs like IndexedDB or fetch. But @phiresky (sql.js-httpvfs) and @jlongster (absurd-sql) independently discovered a clever way to make synchronous calls to asynchronous APIs using Atomics and SharedArrayBuffer. It's pretty cool!

The main catch with these APIs (and why it took so long to get support in Safari again) is they are potentially exploitable by Spectre malware attacks, so they are only enabled on pages served with special COOP/COEP HTTP headers which also heavily restrict including content from a different origin. This may prevent integrating certain third-party features like federated sign-in (e.g. OAuth2) and ads right now.

Implementing a SQLite VFS or module using Atomics and SharedArrayBuffer based on the described methods should be straightforward with the wa-sqlite synchronous build and I would be excited to see it happen. I don't plan to do that myself, however - i.e. I don't plan to add a synchronous IndexedDB (or File System Access) VFS to this repo - at least until it can be made to work with federated sign-in.

@rhashimoto rhashimoto added the faq label Jan 20, 2022
@rhashimoto rhashimoto closed this Jan 20, 2022
@steida
Copy link

@steida steida commented Jan 20, 2022

Can't be a federated sign-in delegated to a server or another domain? I don't know your requirements, but it looks like a one-time action.

@rhashimoto
Copy link
Owner Author

@rhashimoto rhashimoto commented Jan 21, 2022

I don't know enough about OAuth2 to say that is impossible, but I assume a workaround is not trivial as people at WHATWG are trying to fix it. In addition for me personally, my current web app needs only static content hosting, so any solution requiring server logic is a big step I would be reluctant to take.

@steida
Copy link

@steida steida commented Jan 21, 2022

As far I remember, FB API allowed doing a redirect to their server page with redirecting back to my app with some auth in a query. I always preferred that, because I don't line popups.

Repository owner deleted a comment from steida Jan 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
faq
Projects
None yet
Development

No branches or pull requests

2 participants