State.close leaves closed upvalues in the open list, so calls get slower without bound
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 25/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
}
}
- Lingua principale
- Go
- Stelle
- 3.5k
- Fork
- 217
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
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.
Altre issue di Shopify/go-lua
-
Numeric modulo fast path disagrees with Lua 5.2 and the library fallback for negative operandsForse già presa @efegokdemir l’ha presa 35 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
io.write discards spaces after trailing numbersForse già presa @flynn-eye l’ha presa 25 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
-
Difficoltà 3/5 Mezza giornata Idoneità per principianti 18/100
Tutte le issue di Shopify/go-lua
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
docker/model-runner#1118 ·
I maintainer di solito rispondono entro 1 giorno
-
Screenshot missing in READMEAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100