collectRefs: record idents only for tracked objects
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 85/100
- Tipo di issue
- Refactoring
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- go
- Ambito
- devtools, performance
Direzione di ricerca
Inizia da internal/collect.go:447 e confronta collectUnkeyedFields in collect.go:431-438; esamina l’ordinamento di collectTargets in internal/analyzer.go:59-60 e i reader in rename.go:70 e 131. Filtra i record degli identificatori e dei campi correlati sugli tracked objects, mantenendo il comportamento esistente di refs. Il lavoro è completato quando c.idents contiene solo tracked targets e i rename reader continuano a funzionare correttamente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
collectRefs (internal/collect.go:447) appends to c.idents for every Def and every Use in the package. Locals, parameters and objects from the standard library are all included. Only tracked targets are ever read, so the map can hold only those.
Current shape
ast.Inspect(fi.file, func(n ast.Node) bool {
...
if obj := pass.TypesInfo.Defs[ident]; obj != nil {
c.idents[obj] = append(c.idents[obj], ident) // every definition
}
obj := origin(pass.TypesInfo.Uses[ident])
...
c.idents[obj] = append(c.idents[obj], ident) // every use: err, ctx, fmt.Sprintf...
if tn := embeddedTypeName(obj); tn != nil {
c.idents[tn] = append(c.idents[tn], ident)
}
if _, tracked := c.byObj[obj]; tracked { // refs already filters
c.refs[obj] = append(c.refs[obj], ref{node: ident, file: fi})
}
return true
})
The only readers are rename.go:70 and rename.go:131. Both read c.idents[t.obj], where t is a tracked target.
Why the change helps
c.idents grows with every identifier in the package. Each new key allocates a map bucket and a slice. For a package of 50,000 identifiers, that is tens of thousands of allocations whose results nobody reads. This walk runs on every pass, so every user pays for it.
// tracked reports whether obj is a key of c.byObj.
if obj := pass.TypesInfo.Defs[ident]; obj != nil && c.tracked(obj) {
c.idents[obj] = append(c.idents[obj], ident)
}
...
if _, tracked := c.byObj[obj]; tracked {
c.idents[obj] = append(c.idents[obj], ident)
c.refs[obj] = append(c.refs[obj], ref{node: ident, file: fi})
}
if tn := embeddedTypeName(obj); tn != nil && c.tracked(tn) {
c.idents[tn] = append(c.idents[tn], ident)
}
With the filter, the map holds entries only for the declarations declscope checks.
Related
collectUnkeyedFields (collect.go:431-438) also records fields that are not targets. Its comment says so: "refs is only ever read for a target, so the entry is never asked for." The same filter applies there.
Risk
Very low. collectTargets runs before collectRefs (internal/analyzer.go:59-60), so c.byObj is complete when the walk starts. refs already uses the same filter.
Not measured yet.
- Lingua principale
- Go
- Stelle
- 40
- Fork
- 1
- Merge medio
- 51m
- PR unite (30g)
- 113
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.
Issue simili
-
agent-review-finding bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
jordansmall/spindrift#5281 ·
I maintainer di solito rispondono entro 1 giorno
-
unbounded value for n in `/v1/logs` can panic/OOMForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertasmall item
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
canonical/pebble#1127 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[schema-coverage] elasticstack_elasticsearch_synonym_set (data source)Forse già presa @github-actions l’ha presa oggi. Apertaacceptance-tests phase-coding schema-coverage testing triaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 81/100
elastic/terraform-provider-elasticstack#5211 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 89/100
open-policy-agent/opa#9366 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
defect
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
nats-io/nats-server#8752 ·
I maintainer di solito rispondono entro 1 giorno