From b33ad175df2f8624243eacd3fad62fe0184008bb Mon Sep 17 00:00:00 2001 From: Anuraag Agrawal Date: Mon, 17 Oct 2022 17:46:33 +0900 Subject: [PATCH] Allow configuring initial heap and set to 100MB instead of 1MB (#44) --- magefile.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/magefile.go b/magefile.go index 40c8e4846624e..2890934fb5ab5 100644 --- a/magefile.go +++ b/magefile.go @@ -168,11 +168,21 @@ func Build() error { timingBuildTag = "-tags='timing proxywasm_timing'" } + // ~100MB initial heap + initialPages := 2100 + if ipEnv := os.Getenv("INITIAL_PAGES"); ipEnv != "" { + if ip, err := strconv.Atoi(ipEnv); err != nil { + return err + } else { + initialPages = ip + } + } + if err := sh.RunV("tinygo", "build", "-opt=2", "-o", filepath.Join("build", "mainraw.wasm"), "-scheduler=none", "-target=wasi", timingBuildTag); err != nil { return err } - return stubUnusedWasmImports(filepath.Join("build", "mainraw.wasm"), filepath.Join("build", "main.wasm")) + return patchWasm(filepath.Join("build", "mainraw.wasm"), filepath.Join("build", "main.wasm"), initialPages) } // UpdateLibs updates the C++ filter dependencies. @@ -227,7 +237,7 @@ func TeardownExample() error { var Default = Build -func stubUnusedWasmImports(inPath, outPath string) error { +func patchWasm(inPath, outPath string, initialPages int) error { raw, err := os.ReadFile(inPath) if err != nil { return err @@ -237,6 +247,8 @@ func stubUnusedWasmImports(inPath, outPath string) error { return err } + mod.MemorySection.Min = uint32(initialPages) + for _, imp := range mod.ImportSection { switch { case imp.Name == "fd_filestat_get":