Skip to content

Commit 0f2c91d

Browse files
authored
Merge pull request #1505 from 0chain/hotfix/wasm-memory
Tune gc and set extra count to 0 for wasm
2 parents e3f18c0 + 54c12bc commit 0f2c91d

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ gosdk-build: gomod-download
3535
go build -x -v -tags bn256 ./...
3636

3737
wasm-build: getrev
38-
CGO_ENABLED=0 GOOS=js GOARCH=wasm go build -buildvcs=false -o ./zcn.wasm ./wasmsdk
38+
CGO_ENABLED=0 GOOS=js GOARCH=wasm go build -ldflags="-s -w" -buildvcs=false -o ./zcn.wasm ./wasmsdk
3939

4040
wasm-test: wasm-build
4141
env -i $(shell go env) PATH="$(shell go env GOROOT)/misc/wasm:$(PATH)" CGO_ENABLED=0 GOOS=js GOARCH=wasm go test -v github.com/0chain/gosdk/wasmsdk/jsbridge/...

wasmsdk/proxy.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package main
66
import (
77
"errors"
88
"fmt"
9+
"runtime/debug"
910
"sync"
1011
"time"
1112

@@ -271,6 +272,8 @@ func main() {
271272
}
272273

273274
hideLogs()
275+
debug.SetGCPercent(40)
276+
debug.SetMemoryLimit(2.5 * 1024 * 1024 * 1024) //2.5 GB
274277

275278
<-make(chan bool)
276279

zboxcore/sdk/allocation.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ func SetMultiOpBatchSize(size int) {
253253
func SetWasm() {
254254
IsWasm = true
255255
BatchSize = 5
256+
extraCount = 0
256257
}
257258

258259
func getPriceRange(name string) (PriceRange, error) {

zboxcore/sdk/downloadworker.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ import (
3838
const (
3939
DOWNLOAD_CONTENT_FULL = "full"
4040
DOWNLOAD_CONTENT_THUMB = "thumbnail"
41-
EXTRA_COUNT = 2
41+
)
42+
43+
var (
44+
extraCount = 2
4245
)
4346

4447
type DownloadRequestOption func(dr *DownloadRequest)
@@ -531,7 +534,7 @@ func (req *DownloadRequest) processDownload() {
531534
}
532535
req.bufferMap = nil
533536
}()
534-
sz := downloadWorkerCount + EXTRA_COUNT
537+
sz := downloadWorkerCount + extraCount
535538
if sz > n {
536539
sz = n
537540
}
@@ -684,7 +687,7 @@ func (req *DownloadRequest) processDownload() {
684687
firstReqWG := sync.WaitGroup{}
685688
firstReqWG.Add(1)
686689
eg, egCtx := errgroup.WithContext(ctx)
687-
eg.SetLimit(downloadWorkerCount + EXTRA_COUNT)
690+
eg.SetLimit(downloadWorkerCount + extraCount)
688691
for i := 0; i < n; i++ {
689692
j := i
690693
if i == 1 {

0 commit comments

Comments
 (0)