Introduce CallEngine assigned to api.Function implementation. (#761)

This introduces wasm.CallEngine internal type, and assign it to the api.Function
implementations. api.Function.Call now uses that CallEngine assigned to it
to make function calls.

Internally, when creating CallEngine implementation, the compiler engine allocates
call frames and values stack. Previously, we allocate these stacks for each function calls,
which was a severe overhead as we can recognize in the benchmarks. As a result,
this reduces the memory usage (== reduces the GC jobs) as long as we reuse
the same api.Function multiple times.

As a side effect, now api.Function.Call is not goroutine-safe. So this adds the comment
about it on that method.

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
This commit is contained in:
Takeshi Yoneda
2022-08-24 16:11:15 +09:00
committed by GitHub
parent 15686988dc
commit 0bd2beedac
18 changed files with 289 additions and 122 deletions

View File

@@ -272,6 +272,9 @@ type Function interface {
// If Module.Close or Module.CloseWithExitCode were invoked during this call, the error returned may be a
// sys.ExitError. Interpreting this is specific to the module. For example, some "main" functions always call a
// function that exits.
//
// Call is not goroutine-safe, therefore it is recommended to create another Function if you want to invoke
// the same function concurrently. On the other hand, sequential invocations of Call is allowed.
Call(ctx context.Context, params ...uint64) ([]uint64, error)
}