Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

C API - faster calls #397

Open
gektorbr opened this issue Jan 19, 2020 · 3 comments
Open

C API - faster calls #397

gektorbr opened this issue Jan 19, 2020 · 3 comments

Comments

@gektorbr
Copy link

As I understand lucet_instance_run is the only way of calling a wasm function from the a C "host". It "resolves" the function and makes a call to it. Unfortunately this API is extremely slow (~ 10 milliseconds in my case). Is there a way to resolve a function "in advance" and to make fast calls to it later?

@iximeow
Copy link
Contributor

iximeow commented Jan 21, 2020

The short answer is that currently, there is no pre-resolved API (even for non-C users of lucet-runtime). Out of curiosity, about how many functions are in the wasm module you're resolving out of? 10 milliseconds is pretty slow, but that sounds about right from that API in the worst circumstances.

Either way, there should be a faster API, but it hasn't been exposed yet.

It sounds like you might have taken a look at Instance::run, which is the right lifecycle, just all in one function.

So to expose a pre-resolved run_func we'd need to:

  • expose ModuleInternal::get_export_func somehow (probably through Instance? Instance::get_func_by_name?)
  • expose Instance::run_func (which now takes a FunctionHandle - a bit more misuse-resistant than it once was)
  • expose both of these through the C API.

If you'd like to put a PR together to do the above, that would be fantastic! I'd be happy to work with you on that. I'm not sure when we'll get to this, otherwise.

@gektorbr
Copy link
Author

Out of curiosity, about how many functions are in the wasm module you're resolving

Just a couple of functions. The idea is to resolve the functions only once and to call them a lot.

There is lucet_instance_run_func_idx, although there is no API to get function index. Wouldn't it be faster?

@iximeow
Copy link
Contributor

iximeow commented Jan 21, 2020

lucet_instance_run_func_idx is specifically for functions in wasm tables - the missing API to get those indices is because they're determined by the wasm module, we just ensure the wasm module's indices remain valid through compilation. lucet_instance_run_func_idx won't be able to run functions that aren't in the wasm module's indirection table.

That said, if you can add functions to the wasm table you could use the index you know them to be at for lucet_runtime_run_func_idx, though I imagine this would be kind of brittle and toolchain-dependent. I don't entirely recommend this.

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

No branches or pull requests

2 participants