Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

profile: FilterSamplesByName allocates a temporary Location slice per sample unnecessarily

Aperta
#1,058 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@kyyril ci sta già lavorando.

Dal 26/10/2026.

  • #1059 di @kyyril — aperta

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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di google/pprof

Tutte le issue di google/pprof

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.