Skip to content

Commit

Permalink
Allow configuring initial heap and set to 100MB instead of 1MB (envoy…
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraaga authored Oct 17, 2022
1 parent 10fc837 commit b33ad17
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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":
Expand Down

0 comments on commit b33ad17

Please sign in to comment.