State.close leaves closed upvalues in the open list, so calls get slower without bound
Đá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
- 25/100
Hướng nghiên cứu
Read stack.go and trace State.close alongside findUpValue to understand how the open upvalue list is maintained. The issue includes a reproduction and a proposed fix; verify the list no longer retains closed entries and run the relevant Go tests. A pull request is already open for this issue.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
State.close (stack.go) unlinks closed upvalues from l.upValues, but the loop advances p onto the node it has just unlinked:
for e := l.upValues; e != nil; e, p = e.next, e {
if e.upValue.isInStackAbove(level) {
e.upValue.close()
if p != nil {
p.next = e.next
} else {
l.upValues = e.next
}
}
}
When two neighbouring upvalues are closed in the same call, the second unlink writes to the removed node instead of the list. The second upvalue is closed correctly (its value is right), but it stays in the open list forever. Every later findUpValue (on each closure creation) and close walks the longer list, so code that creates closures gets slower the longer a State lives.
Reproduction:
L := lua.NewState()
lua.OpenLibraries(L)
lua.DoString(L, `
local function f()
local a, b, c = 1, 2, 3
local g = function() return a + b + c end
return g()
end
for _ = 1, 100 do f() end`)
// l.upValues now holds 100 dead entries (one per call); it should hold none.
In our use (a planner called a few thousand times per State), the cost per call grew from about 155 µs to about 1.6 ms after 4,000 calls, and profiles were dominated by findUpValue / isInStackAt. With the fix below, the open list stays empty and a long simulation ran 2.2 times faster, with identical results.
Fix: only advance p past nodes that stay in the list.
var p *openUpValue
- for e := l.upValues; e != nil; e, p = e.next, e {
+ for e := l.upValues; e != nil; e = e.next {
if e.upValue.isInStackAbove(level) {
e.upValue.close()
if p != nil {
p.next = e.next
} else {
l.upValues = e.next
}
+ } else {
+ p = e
}
}
- Ngôn ngữ chính
- Go
- Star
- 3.5k
- Fork
- 217
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
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 khác của Shopify/go-lua
-
Numeric modulo fast path disagrees with Lua 5.2 and the library fallback for negative operandsCó thể đã có người làm @efegokdemir đã nhận 35 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
io.write discards spaces after trailing numbersCó thể đã có người làm @flynn-eye đã nhận 25 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
-
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 18/100
Tất cả issue của Shopify/go-lua
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/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 74/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
docker/model-runner#1118 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Screenshot missing in READMEĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100