From d43d571a13bac72a07fe83ec9a01f0352ce91fed Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 1 Aug 2024 07:21:05 -0700 Subject: [PATCH] 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.