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

feat(instance) Add a new wasm_instance.exported_functions field (improve function invocation time by 77%) #70

Merged
merged 3 commits into from
Jul 10, 2019

Conversation

Hywan
Copy link
Contributor

@Hywan Hywan commented Jul 10, 2019

The idea is to cache the exported functions of an instance into an
unordered map, so that we don't need to iterate over all the exports
each time to find an exported function to invoke.

std::unordered_map guarantees that reading an element is O(1).

The idea is to cache the exported functions of an instance into an
unordered map, so that we don't need to iterate over all the exports
each time to find an exported function to invoke.

`std::unordered_map` guarantees that reading an element is O(1).
@Hywan Hywan added 🎉 enhancement New feature or request 📦 component-extension About the PHP extension written in C/C++ labels Jul 10, 2019
@Hywan Hywan self-assigned this Jul 10, 2019
@Hywan
Copy link
Contributor Author

Hywan commented Jul 10, 2019

bors try

bors bot added a commit that referenced this pull request Jul 10, 2019
@bors
Copy link
Contributor

bors bot commented Jul 10, 2019

try

Build succeeded

`wasm_instance.exported_functions` is now a map from string to
`wasm_exported_function`. This latter new structure holds the opaque
pointer to `wasmer_export_func_t`. It also holds the sinature (inputs
and outputs) of the exported function.

The idea is to avoid collecting those information every time an
exported function is invoked. It also avoids memory allocations.
@Hywan
Copy link
Contributor Author

Hywan commented Jul 10, 2019

bors try

bors bot added a commit that referenced this pull request Jul 10, 2019
@bors
Copy link
Contributor

bors bot commented Jul 10, 2019

try

Build succeeded

@Hywan
Copy link
Contributor Author

Hywan commented Jul 10, 2019

The InvokeFunction benchmark can help to measure the improvement here.

Before:

subject params revs its mem_peak mean mode best rstdev
bench_invoke_sum [] 1000 10 1,421,000b 8.169μs 8.177μs 7.752μs 2.12%
bench_invoke_i32_i64_f32_f64_f64 [] 1000 10 1,421,000b 8.217μs 8.143μs 7.997μs 2.92%

After:

subject params revs its mem_peak mean mode best rstdev
bench_invoke_sum [] 1000 10 1,421,000b 1.821μs 1.799μs 1.758μs 3.77%
bench_invoke_i32_i64_f32_f64_f64 [] 1000 10 1,421,000b 1.983μs 1.926μs 1.875μs 6.51%

It's 4.3 times faster to invoke a function (or 77% faster)! That's nice :-).

@Hywan Hywan marked this pull request as ready for review July 10, 2019 13:28
@Hywan Hywan changed the title feat(instance) Add a new wasm_instance.exported_functions field. feat(instance) Add a new wasm_instance.exported_functions field (improve function invocation time by 77%) Jul 10, 2019
@Hywan
Copy link
Contributor Author

Hywan commented Jul 10, 2019

bors r+

bors bot added a commit that referenced this pull request Jul 10, 2019
70: feat(instance) Add a new `wasm_instance.exported_functions` field (improve function invocation time by 77%) r=Hywan a=Hywan

The idea is to cache the exported functions of an instance into an
unordered map, so that we don't need to iterate over all the exports
each time to find an exported function to invoke.

`std::unordered_map` guarantees that reading an element is O(1).

Co-authored-by: Ivan Enderlin <ivan.enderlin@hoa-project.net>
@bors
Copy link
Contributor

bors bot commented Jul 10, 2019

Build succeeded

@bors bors bot merged commit 34b079d into master Jul 10, 2019
@bors bors bot deleted the feat-instance-exports-cache branch July 10, 2019 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 component-extension About the PHP extension written in C/C++ 🎉 enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant