wasm: dead pointers in GC stack slots keep garbage alive
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- go, wasm
- Ambito
- compilers, performance
Direzione di ricerca
Start by reading MakeGCStackSlots and how it handles pointer liveness, then trace the existing cyclic phi handling. The issue describes the needed clearing points: after a value’s last use in a block where it is not live out, and at successor block entry when it stops being live. Use the provided strings.Fields reproducer and run the WASI and WebAssembly tests; done means dead pointers are cleared without breaking those tests.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
On wasm, MakeGCStackSlots gives every tracked pointer in a function its own slot in gc.stackobject and stores the pointer there when it is created. The slot is never cleared. A pointer that is no longer used stays in its slot until the same instruction runs again, so the GC keeps the object alive.
This makes strings.Fields on 1 MB about 50 times slower on wasip1 than natively when the results are thrown away. The previous call's []string stays rooted. Every collection then looks up each of its 128K strings, and each lookup scans findHead through the 1 MB input they all point into.
Reproducer:
package main
import (
"strings"
"time"
)
func main() {
x := make([]byte, 1<<20)
seed := uint32(99)
for i := range x {
seed ^= seed << 13
seed ^= seed >> 17
seed ^= seed << 5
if seed%7 == 0 {
x[i] = ' '
} else {
x[i] = 'a' + byte(seed%26)
}
}
data := string(x)
start := time.Now()
total := 0
for i := 0; i < 20; i++ {
total += len(strings.Fields(data))
}
println(total, time.Since(start).Milliseconds(), "ms")
}
| time | markRoot lookups | blocks scanned by findHead | |
|---|---|---|---|
| darwin/arm64 -gc=precise | 37 ms | 17 | 33K |
| wasip1 | 2770 ms | 643K | 21G |
Measured on a branch based on dev, with counters added to markRoot.
In this program strings.Fields is inlined into main. Only len of the result is used, but the result pointer is stored into slot 49 of main's stack object. The next iteration's make([]string, n) can trigger a collection while slot 49 still holds the old slice. Natively the old result is dead and is not seen by the stack scan.
The findHead cost is quadratic and is a separate problem (it also shows natively when the results are kept). The stale slot is what makes wasm hit it in a loop that should not.
Possible fix: clear slots when their value dies. After MakeGCStackSlots stores the tracked pointers, compute the liveness of each one and store null into its slot where it stops being live. That means after the last use in a block where it is not live out, and at the start of a successor block where it stops being live.
- Interior pointers (GEPs with an offset) are not tracked, so a value stays live while anything computed from it without its own slot is still used. Values with no pointer in their type do not count, as
uintptrdoes not keep objects alive in Go. - Phis in loops need the same care as today's cyclic phi handling.
- LLVM keeps these stores. The stack object escapes through
runtime.stackChainStartandruntime.allochas no memory attribute, so a null store can only be removed when no later allocation could see it, which is when it does not matter.
A prototype of this takes the reproducer from 2770 ms to 54 ms on wasip1 and passes the WASI and WebAssembly tests. It does not cover two other places stale pointers can hide: stack memory outside the slots, which is scanned conservatively, and the asyncify save buffer of a suspended goroutine.
- Lingua principale
- Go
- Stelle
- 17.8k
- Fork
- 1.1k
- Merge medio
- 1g 4h
- PR unite (30g)
- 380
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di tinygo-org/tinygo
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
tinygo-org/tinygo#6727 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
tinygo-org/tinygo#6711 ·
I maintainer di solito rispondono entro 1 giorno
-
Builds are not reproducible: cgo snippet paths in debug infoForse già presa @tridev-tej l’ha presa 1 giorno fa. Apertaenhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
tinygo-org/tinygo#6619 ·
I maintainer di solito rispondono entro 1 giorno
-
Fix the targets that tinygo build -target rejectsForse già presa @narguis l’ha presa 2 giorni fa. Apertabug good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
tinygo-org/tinygo#6617 · 5 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
tinygo-org/tinygo#6312 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di tinygo-org/tinygo
Issue simili
-
release
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
github/gh-aw-mcpg#17603 ·
I maintainer di solito rispondono entro 1 giorno
-
help wanted
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 94/100
oras-project/oras-go#1827 ·
I maintainer di solito rispondono entro 1 giorno
-
docs: database/sql Sessions example never commits its batch, and its "Full Example" link is a 404Apertadocumentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
ClickHouse/clickhouse-go#2185 ·
I maintainer di solito rispondono entro 1 giorno
-
bug needs triage receiver/podman
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
open-telemetry/opentelemetry-collector-contrib#53700 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
tagvalue.Read fails with "token too long" on lines over 64 KiBForse già presa @G26karthik l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
spdx/tools-golang#319 ·