From d43d571a13bac72a07fe83ec9a01f0352ce91fed Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 1 Aug 2024 07:21:05 -0700 Subject: [PATCH 1/6] doc: adds comments on simultaneous compilation Signed-off-by: Takeshi Yoneda --- cache.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cache.go b/cache.go index 2d1b4e3b9c..6da8d52188 100644 --- a/cache.go +++ b/cache.go @@ -24,6 +24,12 @@ import ( // All implementations are in wazero. // - Instances of this can be reused across multiple runtimes, if configured // via RuntimeConfig. +// - The cache check happens before the compilation, so if multiple Goroutines are +// trying to compile the same module simultaneously, it is possible that they +// all compile the module. The design here is that the lock isn't held for the action "Compile" +// but only for saving the result. Therefore, we strongly recommend that the embedder +// does the centralized compilation in a single goroutine to generate cache rather than +// trying to Compile in parallel for a single module. type CompilationCache interface{ api.Closer } // NewCompilationCache returns a new CompilationCache to be passed to RuntimeConfig. From 806ce71cf220812d94a50238a22ce7758ccc4a92 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 1 Aug 2024 07:23:06 -0700 Subject: [PATCH 2/6] more Signed-off-by: Takeshi Yoneda --- cache.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache.go b/cache.go index 6da8d52188..d94b1ae69b 100644 --- a/cache.go +++ b/cache.go @@ -27,7 +27,7 @@ import ( // - The cache check happens before the compilation, so if multiple Goroutines are // trying to compile the same module simultaneously, it is possible that they // all compile the module. The design here is that the lock isn't held for the action "Compile" -// but only for saving the result. Therefore, we strongly recommend that the embedder +// but only for checking and saving the compiled result. Therefore, we strongly recommend that the embedder // does the centralized compilation in a single goroutine to generate cache rather than // trying to Compile in parallel for a single module. type CompilationCache interface{ api.Closer } From e00af5874577d445e806b3cefdab6cbaa254e1ad Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 1 Aug 2024 07:23:58 -0700 Subject: [PATCH 3/6] more Signed-off-by: Takeshi Yoneda --- cache.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cache.go b/cache.go index d94b1ae69b..dd8656e0c5 100644 --- a/cache.go +++ b/cache.go @@ -29,7 +29,8 @@ import ( // all compile the module. The design here is that the lock isn't held for the action "Compile" // but only for checking and saving the compiled result. Therefore, we strongly recommend that the embedder // does the centralized compilation in a single goroutine to generate cache rather than -// trying to Compile in parallel for a single module. +// trying to Compile in parallel for a single module. In other words, we always recommend to produce CompiledModule +// share it across multiple goroutines to avoid trying to compile the same module simultaneously. type CompilationCache interface{ api.Closer } // NewCompilationCache returns a new CompilationCache to be passed to RuntimeConfig. From e5bdbf2ab2d7b84f14f5a59fa609fa899af066cd Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 1 Aug 2024 07:25:11 -0700 Subject: [PATCH 4/6] more Signed-off-by: Takeshi Yoneda --- cache.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache.go b/cache.go index dd8656e0c5..9e99b04027 100644 --- a/cache.go +++ b/cache.go @@ -28,7 +28,7 @@ import ( // trying to compile the same module simultaneously, it is possible that they // all compile the module. The design here is that the lock isn't held for the action "Compile" // but only for checking and saving the compiled result. Therefore, we strongly recommend that the embedder -// does the centralized compilation in a single goroutine to generate cache rather than +// does the centralized compilation in a single goroutine (or multiple gorutines per Wasm binary) to generate cache rather than // trying to Compile in parallel for a single module. In other words, we always recommend to produce CompiledModule // share it across multiple goroutines to avoid trying to compile the same module simultaneously. type CompilationCache interface{ api.Closer } From a150d613eb45a403d4559f188c1de78d898d6e39 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 1 Aug 2024 07:25:21 -0700 Subject: [PATCH 5/6] more Signed-off-by: Takeshi Yoneda --- cache.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache.go b/cache.go index 9e99b04027..34d934fa2d 100644 --- a/cache.go +++ b/cache.go @@ -28,7 +28,7 @@ import ( // trying to compile the same module simultaneously, it is possible that they // all compile the module. The design here is that the lock isn't held for the action "Compile" // but only for checking and saving the compiled result. Therefore, we strongly recommend that the embedder -// does the centralized compilation in a single goroutine (or multiple gorutines per Wasm binary) to generate cache rather than +// does the centralized compilation in a single goroutine (or multiple Goroutines per Wasm binary) to generate cache rather than // trying to Compile in parallel for a single module. In other words, we always recommend to produce CompiledModule // share it across multiple goroutines to avoid trying to compile the same module simultaneously. type CompilationCache interface{ api.Closer } From fd9b5c7f4b4e77fcc7910e96dcef80356fddf7d9 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 1 Aug 2024 07:25:27 -0700 Subject: [PATCH 6/6] more Signed-off-by: Takeshi Yoneda --- cache.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cache.go b/cache.go index 34d934fa2d..83cdb94ef3 100644 --- a/cache.go +++ b/cache.go @@ -28,9 +28,9 @@ import ( // trying to compile the same module simultaneously, it is possible that they // all compile the module. The design here is that the lock isn't held for the action "Compile" // but only for checking and saving the compiled result. Therefore, we strongly recommend that the embedder -// does the centralized compilation in a single goroutine (or multiple Goroutines per Wasm binary) to generate cache rather than +// does the centralized compilation in a single Goroutines (or multiple Goroutines per Wasm binary) to generate cache rather than // trying to Compile in parallel for a single module. In other words, we always recommend to produce CompiledModule -// share it across multiple goroutines to avoid trying to compile the same module simultaneously. +// share it across multiple Goroutines to avoid trying to compile the same module simultaneously. type CompilationCache interface{ api.Closer } // NewCompilationCache returns a new CompilationCache to be passed to RuntimeConfig.