Skip to content

Commit bc7338a

Browse files
authored
Merge pull request #475 from metrico/micro_gc
Micro gc
2 parents 9d5d9cd + 9139b44 commit bc7338a

File tree

3 files changed

+17
-33
lines changed

3 files changed

+17
-33
lines changed

wasm_parts/main.go

+17-23
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ import (
2121
"wasm_parts/types"
2222
)
2323

24-
//go:linkname get sync.(*Pool).Get
25-
func get(p *sync.Pool) any {
26-
panic("GET POOL")
27-
}
28-
2924
var maxSamples = 5000000
3025

3126
type ctx struct {
@@ -445,11 +440,12 @@ type TestSeries struct {
445440
data []byte
446441
stepMs int64
447442

448-
labels labels.Labels
449-
tsMs int64
450-
generatedMs int64
451-
val float64
452-
i int
443+
labels labels.Labels
444+
tsMs int64
445+
val float64
446+
i int
447+
448+
state int
453449
}
454450

455451
func (t *TestSeries) reset() {
@@ -462,23 +458,21 @@ func (t *TestSeries) reset() {
462458

463459
func (t *TestSeries) Next() bool {
464460
if t.i*16 >= len(t.data) {
465-
if t.generatedMs == 0 {
466-
t.tsMs += t.stepMs
467-
t.generatedMs += t.stepMs
468-
return true
469-
}
470461
return false
471462
}
472463
ts := *(*int64)(unsafe.Pointer(&t.data[t.i*16]))
473-
if ts-t.tsMs > t.stepMs && t.generatedMs < 300000 {
464+
if t.state == 1 {
474465
t.tsMs += t.stepMs
475-
t.generatedMs += t.stepMs
476-
return true
466+
if t.tsMs >= ts {
467+
t.state = 0
468+
}
469+
}
470+
if t.state == 0 {
471+
t.tsMs = ts
472+
t.val = *(*float64)(unsafe.Pointer(&t.data[t.i*16+8]))
473+
t.i++
474+
t.state = 1
477475
}
478-
t.tsMs = ts
479-
t.generatedMs = 0
480-
t.val = *(*float64)(unsafe.Pointer(&t.data[t.i*16+8]))
481-
t.i++
482476
return true
483477
}
484478

@@ -496,7 +490,7 @@ func (t *TestSeries) Seek(tmMS int64) bool {
496490
if t.i < 0 {
497491
t.i = 0
498492
}
499-
t.tsMs = tmMS
493+
t.tsMs = ms
500494
t.val = *(*float64)(unsafe.Pointer(&t.data[t.i*16+8]))
501495
t.i++
502496
return true

wasm_parts/main.js

-10
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,10 @@ const getWasm = (() => {
1313
const _Go = Go
1414
var go = new _Go();
1515
let wasm = null
16-
let cnt = 0
17-
let run = false
18-
let int
1916
async function init () {
2017
go = new _Go();
21-
run = true
2218
const _wasm = await WebAssembly.instantiate(
2319
gunzipSync(fs.readFileSync(WASM_URL)), go.importObject)
24-
int && clearInterval(int)
25-
int = setInterval(() => {
26-
console.log(`WASM SIZE: ${Math.floor(wasm.exports.memory.buffer.byteLength / 1024 / 1024)} MB`)
27-
}, 5000)
2820
go.run(_wasm.instance)
2921
wasm = _wasm.instance
3022
wasm.exports.setMaxSamples(process.env.ADVANCED_PROMETHEUS_MAX_SAMPLES || 5000000)
@@ -41,8 +33,6 @@ const getWasm = (() => {
4133
}]
4234
})
4335
)
44-
cnt = 0
45-
run = false
4636
}
4737
init()
4838
return () => {

wasm_parts/main.wasm.gz

10.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)