Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Commit

Permalink
Initialize descriptor cache in initHeap (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraaga authored Nov 28, 2023
1 parent a3593a7 commit c808055
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ jobs:
if: ${{ startsWith(matrix.os, 'ubuntu-') }}

- run: go run mage.go test

- run: go run mage.go e2eGzip
7 changes: 7 additions & 0 deletions e2e/gzip/go.mod
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions e2e/gzip/go.sum
Original file line number Diff line number Diff line change
@@ -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=
16 changes: 16 additions & 0 deletions e2e/gzip/main.go
Original file line number Diff line number Diff line change
@@ -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)
}
4 changes: 3 additions & 1 deletion gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const (
gcDsBitmap = uintptr(1)
)

var descriptorCache = newIntMap()
var descriptorCache intMap

//export onCollectionEvent
func onCollectionEvent(eventType uint32) {
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions go.work
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ use (
.
./bench
./e2e/envoy-dispatch-call
./e2e/gzip
./e2e/higress-gc-test
)
17 changes: 17 additions & 0 deletions magefiles/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit c808055

Please sign in to comment.