Add compilation cache functionality and Close on CompiledCode. (#457)
Thanks to #454, now the compiled binary (code segment) can be reused for multiple module instances originating from the same source (wasm.Module). This commit introduces the caching mechanism on engine where it caches compiled functions keyed on `wasm.Module`. As a result, this allows us to do the fast module instantiation from the same *CompiledCode. In order to release the cache properly, this also adds `Close` method on CompiledCode. Here's some bench result for instantiating multiple modules from the same CompiledCode: ``` name old time/op new time/op delta Initialization/interpreter-32 2.84ms ± 3% 0.06ms ± 1% -97.73% (p=0.008 n=5+5) Initialization/jit-32 10.7ms ±18% 0.1ms ± 1% -99.52% (p=0.008 n=5+5) name old alloc/op new alloc/op delta Initialization/interpreter-32 1.25MB ± 0% 0.15MB ± 0% -88.41% (p=0.008 n=5+5) Initialization/jit-32 4.46MB ± 0% 0.15MB ± 0% -96.69% (p=0.008 n=5+5) name old allocs/op new allocs/op delta Initialization/interpreter-32 35.2k ± 0% 0.3k ± 0% -99.29% (p=0.008 n=5+5) Initialization/jit-32 94.1k ± 0% 0.2k ± 0% -99.74% (p=0.008 n=5+5) ``` Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
This commit is contained in:
@@ -407,7 +407,7 @@ type catchFunctions struct {
|
||||
}
|
||||
|
||||
// NewModuleEngine implements the same method as documented on wasm.Engine.
|
||||
func (e *catchFunctions) NewModuleEngine(_ string, _, functions []*wasm.FunctionInstance, _ *wasm.TableInstance, _ map[wasm.Index]wasm.Index) (wasm.ModuleEngine, error) {
|
||||
func (e *catchFunctions) NewModuleEngine(_ string, _ *wasm.Module, _, functions []*wasm.FunctionInstance, _ *wasm.TableInstance, _ map[wasm.Index]wasm.Index) (wasm.ModuleEngine, error) {
|
||||
e.functions = functions
|
||||
return e, nil
|
||||
}
|
||||
@@ -423,5 +423,7 @@ func (e *catchFunctions) Call(_ *wasm.ModuleContext, _ *wasm.FunctionInstance, _
|
||||
}
|
||||
|
||||
// Close implements the same method as documented on wasm.ModuleEngine.
|
||||
func (e *catchFunctions) Close() {
|
||||
}
|
||||
func (e *catchFunctions) Close() {}
|
||||
|
||||
// ReleaseCompilationCache implements the same method as documented on wasm.Engine.
|
||||
func (e *catchFunctions) ReleaseCompilationCache(*wasm.Module) {}
|
||||
|
||||
Reference in New Issue
Block a user