Skip to content

Commit

Permalink
Optimisations On 10M Calls (#288)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
martindevans authored Jan 2, 2024
1 parent 6b926f8 commit bd71441
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 275 deletions.
Loading

0 comments on commit bd71441

Please sign in to comment.