profile: FilterSamplesByName allocates a temporary Location slice per sample unnecessarily
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 1/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 35/100
- Tipo di issue
- Refactoring
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- go
- Ambito
- performance
Direzione di ricerca
The issue identifies FilterSamplesByName in profile/filter.go and includes the current filtering loop and a benchmark. Read that function and check how it filters locations for hide and show; run the existing relevant tests and benchmarks before and after the change. Done means reusing each sample's location backing array and confirming the filtering behavior and benchmark results; linked pull request #1059 is already open.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Context & Discovery
While profiling sample filtering and graph generation paths during recent profile analysis (following work on #1057), we observed that FilterSamplesByName in profile/filter.go incurs repetitive heap allocations across focused samples whenever location filters (hide or show) are applied.
Summary
FilterSamplesByName allocates a new nil slice (var locs []*Location) for every focused sample when hide or show filters are active, even though the sample's own Location backing array always has sufficient capacity.
Details
When len(hidden) > 0, the current code does:
var locs []*Location
for _, loc := range sample.Location {
if !hidden[loc.ID] {
locs = append(locs, loc)
}
}
sample.Location = locs
var locs []*Location starts as a nil slice. The first append that writes an element triggers a heap allocation for a new backing array. However, the sample can only keep a subset of its original locations, so cap(sample.Location) is always sufficient. We can reuse the existing backing array:
locs := sample.Location[:0]
for _, loc := range sample.Location {
if !hidden[loc.ID] {
locs = append(locs, loc)
}
}
sample.Location = locs
This eliminates per-sample heap allocations when filtering locations in-place. The backing array capacity is preserved, so append never needs to reallocate.
Benchmark
Measured on AMD Ryzen 5 6600H (goos: windows, goarch: amd64):
name old ns/op new ns/op delta
FilterSamplesByName/sparse_hide 20.1ms 13.5ms -32.9%
FilterSamplesByName/dense_hide 20.1ms 12.8ms -36.1%
name old B/op new B/op delta
FilterSamplesByName/sparse_hide 1364 KB 1362 KB -0.3%
FilterSamplesByName/dense_hide 1367 KB 1361 KB -0.4%
The improvement holds for both sparse (few hidden locations) and dense (many hidden locations per sample) patterns.
- Lingua principale
- Go
- Stelle
- 9.3k
- Fork
- 683
- Merge medio
- 1g 21h
- PR unite (30g)
- 11
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
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 google/pprof
-
report: trimPath repeatedly splits and allocates path prefixes across functionsForse già presa @kyyril l’ha presa 4 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 25/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
google/pprof#1029 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 74/100
google/pprof#1020 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
pprof cannot locate source code for the list command in common Go setupsForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
google/pprof#1009 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Label with zero int64 value and no unit get dropped during decodingForse già presa @ms-hujia l’ha presa 135 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
google/pprof#1002 · 6 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di google/pprof
Issue simili
-
bug from-studio
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
esengine/DeepSeek-Reasonix#14868 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
project-zot/zot#4636 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
keyxmakerx/Chronicle#1911 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
eugenioenko/ttt#1293 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
needs/area needs/kind needs/priority
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
I maintainer di solito rispondono entro 1 giorno