Skip to content

Commit bd71441

Browse files
authored
Optimisations On 10M Calls (#288)
* Optimisations based on profiling a simple program that loops and makes 10M calls back into C#. Runtime of this test program was 350ms initially. `FromCallback` has been modified to use the store initially used to create the callback, instead of retrieving it from the caller context. In cases where the `Caller` is not required this skips creating the `Caller` (in turn skipping a call to `wasmtime_caller_context`) and skips accessing the store from the caller (in turn skipping `GCHandle.FromIntPtr` to retrieve the `Store` object). Overall this reduced the total execution time down from 350ms to 272ms. `Store` has been modified to fetch the `contextHandle` when first created. The docs (https://docs.wasmtime.dev/c-api/structwasmtime__context.html) state that the context handle lifetime is the same as the store lifetime, so it should be safe to keep it as long as the store is checked before accessing the context. This is achieved by checking `handle.IsInvalid` in the `Context` property. Doing all of this skips a call to `wasmtime_store_context` every time `Context` is accessed. Overall this reduced total execution from time down from 272ms to 208ms. * Fixed IsInvalid/IsClosed in Store.Context property
1 parent 6b926f8 commit bd71441

File tree

5 files changed

+103
-275
lines changed

5 files changed

+103
-275
lines changed

0 commit comments

Comments
 (0)