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

Implement a WebAssembly runner function #17

Closed
psarna opened this issue Oct 5, 2022 · 3 comments · Fixed by #45
Closed

Implement a WebAssembly runner function #17

psarna opened this issue Oct 5, 2022 · 3 comments · Fixed by #45
Assignees

Comments

@psarna
Copy link
Collaborator

psarna commented Oct 5, 2022

A user-defined function capable of running WebAssembly code should be defined (and registered with sqlite3_create_function).

Its final specification should be subject to discussion, but the proposed format could look like that (pseudo-code):

fn run_wasm(wasm_module: blob, function_name: string, args...)

The function would accept a blob with compiled WebAssembly as its first argument, the Wasm function name to look up and execute as the second argument, and forward the rest of the arguments as is to this Wasm function to be executed.

This function can later be a foundation for allowing users to create and register arbitrary Wasm functions right from the CQL interface (esp. with some syntactic sugar to make it pretty: #18).

An important design decision is to pick a WebAssembly runtime for executing the modules. A preliminary list to consider:

Right now I'm biased in favor of wasmtime, but since I saw @losfair's activity in this repository (welcome!!!) I can't resist asking - would you recommend wasmer instead? Any recommmendations for/against it?

@losfair
Copy link

losfair commented Oct 5, 2022

The advantage of choosing Wasmer IMO is mainly the Singlepass backend - it helps with the compilation speed for functions that are large or only need to run once.

Haven't checked the Cranelift backend performance for a while - I would assume they are evolving towards similar numbers ATM.

@losfair
Copy link

losfair commented Oct 5, 2022

Wasmtime and Wasmer both support wasm-c-api (with some custom extensions) btw. #ifdef-ing away the differences and supporting both runtimes shouldn't be too much work.

@psarna psarna self-assigned this Oct 6, 2022
@psarna
Copy link
Collaborator Author

psarna commented Oct 7, 2022

I gathered my experiments in a repository: https://github.com/psarna/libsql_run_wasm_example. I'll later proceed with integrating it into libSQL core, but that will be lots of preprocessor macros and configuration boilerplate to make sure that it also builds fine for people not interested in WebAssembly integration. And the feature itself should definitely be opt-in during compilation, because the Wasm runtime weighs an order of magnitude more than the entire sqlite3 codebase.

penberg added a commit to penberg/libsql that referenced this issue Jun 19, 2023
MarinPostma pushed a commit that referenced this issue Oct 17, 2023
fly: simplify user guide by switching to the HTTP API
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

Successfully merging a pull request may close this issue.

2 participants