State.close leaves closed upvalues in the open list, so calls get slower without bound
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 25/100
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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
}
}
- Linguagem predominante
- Go
- Estrelas
- 3.5k
- Forks
- 217
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Preparar o ambiente
Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de Shopify/go-lua
-
Numeric modulo fast path disagrees with Lua 5.2 and the library fallback for negative operandsTalvez já em andamento @efegokdemir assumiu há 35 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
-
io.write discards spaces after trailing numbersTalvez já em andamento @flynn-eye assumiu há 25 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
-
enhancement
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 25/100
-
Dificuldade 3/5 Meio dia Facilidade para iniciantes 18/100
Todas as issues de Shopify/go-lua
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
limitlessprojects/Go-Hybrid#4764 ·
Mantenedores costumam responder em até 1 dia
-
[bug]: lint fails on main, generated CLI docs out of dateTalvez já em andamento @bupd assumiu hoje. Abertabug documentation
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 85/100
goharbor/harbor-cli#1180 ·
Mantenedores costumam responder em até 1 dia
-
crane: mutate --env adds duplicate PATH on Windows images when key case differsTalvez já em andamento @aad1tyaaaaa assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
google/go-containerregistry#2523 ·
Mantenedores costumam responder em até 4 dias
-
bosh_io_stemcell_type: regular does not work for noble and resolute as it adds -go_agent as suffixAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100
cloudfoundry/bosh-deployment-resource#138 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100