From c808055eec30e714f5122e3a4df957177b12b25a Mon Sep 17 00:00:00 2001 From: Anuraag Agrawal Date: Tue, 28 Nov 2023 12:38:43 +0900 Subject: [PATCH] Initialize descriptor cache in initHeap (#42) --- .github/workflows/ci.yaml | 2 ++ e2e/gzip/go.mod | 7 +++++++ e2e/gzip/go.sum | 4 ++++ e2e/gzip/main.go | 16 ++++++++++++++++ gc.go | 4 +++- go.work | 1 + magefiles/e2e.go | 17 +++++++++++++++++ 7 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 e2e/gzip/go.mod create mode 100644 e2e/gzip/go.sum create mode 100644 e2e/gzip/main.go diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 722c8ab..521165a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -35,3 +35,5 @@ jobs: if: ${{ startsWith(matrix.os, 'ubuntu-') }} - run: go run mage.go test + + - run: go run mage.go e2eGzip diff --git a/e2e/gzip/go.mod b/e2e/gzip/go.mod new file mode 100644 index 0000000..3dbe338 --- /dev/null +++ b/e2e/gzip/go.mod @@ -0,0 +1,7 @@ +module gzip-test + +go 1.20 + +require github.com/wasilibs/nottinygc v0.7.0 + +require github.com/magefile/mage v1.14.0 // indirect diff --git a/e2e/gzip/go.sum b/e2e/gzip/go.sum new file mode 100644 index 0000000..a159767 --- /dev/null +++ b/e2e/gzip/go.sum @@ -0,0 +1,4 @@ +github.com/magefile/mage v1.14.0 h1:6QDX3g6z1YvJ4olPhT1wksUcSa/V0a1B+pJb73fBjyo= +github.com/magefile/mage v1.14.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= +github.com/wasilibs/nottinygc v0.7.0 h1:x8PiLXMHiSx8v4MgyL8T4LEp0FqrPtqZDsveI9xiY3M= +github.com/wasilibs/nottinygc v0.7.0/go.mod h1:oDcIotskuYNMpqMF23l7Z8uzD4TC0WXHK8jetlB3HIo= diff --git a/e2e/gzip/main.go b/e2e/gzip/main.go new file mode 100644 index 0000000..b5a3a73 --- /dev/null +++ b/e2e/gzip/main.go @@ -0,0 +1,16 @@ +// Copyright wasilibs authors +// SPDX-License-Identifier: MIT + +package main + +import ( + "bytes" + "compress/gzip" + + _ "github.com/wasilibs/nottinygc" +) + +func main() { + r := bytes.NewReader([]byte{}) + gzip.NewReader(r) +} diff --git a/gc.go b/gc.go index ec48407..1adc972 100644 --- a/gc.go +++ b/gc.go @@ -46,7 +46,7 @@ const ( gcDsBitmap = uintptr(1) ) -var descriptorCache = newIntMap() +var descriptorCache intMap //export onCollectionEvent func onCollectionEvent(eventType uint32) { @@ -60,6 +60,8 @@ func onCollectionEvent(eventType uint32) { // //go:linkname initHeap runtime.initHeap func initHeap() { + descriptorCache = newIntMap() + C.GC_set_on_collection_event(C.onCollectionEvent) // We avoid overhead in calling GC_make_descriptor on every allocation by implementing // the bitmap computation in Go, but we need to call it at least once to initialize diff --git a/go.work b/go.work index f7ef226..e5cb3ae 100644 --- a/go.work +++ b/go.work @@ -6,5 +6,6 @@ use ( . ./bench ./e2e/envoy-dispatch-call + ./e2e/gzip ./e2e/higress-gc-test ) diff --git a/magefiles/e2e.go b/magefiles/e2e.go index 8f7fa47..0f91d93 100644 --- a/magefiles/e2e.go +++ b/magefiles/e2e.go @@ -159,6 +159,23 @@ func E2eHigressGCTest() error { return nil } +func E2eGzip() error { + if err := os.MkdirAll(filepath.Join("e2e", "gzip", "build"), 0o755); err != nil { + return err + } + + if err := sh.RunV("tinygo", "build", "-target=wasi", "-gc=custom", "-tags='custommalloc'", "-scheduler=none", + "-o", filepath.Join("e2e", "gzip", "build", "main.wasm"), "./e2e/gzip"); err != nil { + return err + } + + if err := sh.RunV("wasmtime", filepath.Join("e2e", "gzip", "build", "main.wasm")); err != nil { + return err + } + + return nil +} + type counterStat struct { Name string `json:"name"` Value int `json:"value"`