collectRefs: record idents only for tracked objects
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 85/100
- Loại issue
- Tái cấu trúc
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- go
- Lĩnh vực
- devtools, performance
Hướng nghiên cứu
Bắt đầu tại internal/collect.go:447 và so sánh collectUnkeyedFields trong collect.go:431-438; kiểm tra thứ tự của collectTargets trong internal/analyzer.go:59-60 và các readers trong rename.go:70 và 131. Lọc các bản ghi identifier và field liên quan để chỉ giữ lại tracked objects, đồng thời bảo toàn hành vi hiện có của refs. Hoàn tất khi c.idents chỉ chứa tracked targets và các rename readers vẫn hoạt động chính xác.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Go
- Star
- 40
- Fork
- 1
- Merge trung bình
- 51 phút
- Pull request đã merge (30 ngày)
- 113
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Add SolentaCó thể đã có người làm @sharmao07 đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
slavakurilyak/awesome-ai-agents#760 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
agent-review-finding bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
jordansmall/spindrift#5281 ·
Maintainer thường phản hồi trong vòng 1 ngày