4 ms·
I find it hard to fathom that many programming languages still don't use partial evaluation. That a popular language avoids inlining is even beyond that. Inlin
by bjoli 6y ago
I find it hard to fathom that many programming languages still don't use partial evaluation. That a popular language avoids inlining is even beyond that.
Inlining us hard to do in ways that makes sure you always produce the optimal code, but simple conservative inlining is probably among the simplest and most efficient optimisations you can do.
Edit: one of my favourite quotes is about the hardships of the heuristics of inliners: "I don't know how many of you have tried to write a good inliner. It is like barely being able to restrain a rabid dog on a leash".
I probably mangled that, but originally it is a quote by Andy Wingo when talking about the improved optimisations of guile 2.2.
- kjksf 6y agoGo does inlining and their inlining heuristic has been tweaked over time.
- bjoli 6y agoThe example in the article is a typical function where I would expect inlining. Overly shy seems almost like an understatement.
- Thaxll 6y agoYou can see the reason actually: go build -gcflags="-m -m" . # _/tmp/inline ./main.go:7:6: cannot inline sum: unhandled op RANGE ./main.go:15:6: can inline fun as: func() uint64 { x := []uint64 literal; return sum(x) } ./main.go:3:6: can inline main as: func() { _ = fun() } ./main.go:4:9: inlining call to fun func() uint64 { x := []uint64 literal; return sum(x) } ./main.go:7:10: sum x does not escape ./main.go:4:9: main []uint64 literal does not escape ./main.go:16:15: fun []uint64 literal does not escape package main func main() { _ = fun() } func sum(x []uint64) uint64 { var sum = uint64(0) for _, v := range x { sum += v } return sum } func fun() uint64 { x := []uint64{10, 20, 30} return sum(x) } Go does not inline range operation.
- uryga 6y ago> Go does not inline range operation. do you know why? [not super familiar with Go, just curious]
- Thaxll 6y agoI'm not sure I think it's just a current limitation: https://github.com/golang/go/wiki/CompilerOptimizations#function-inlining https://github.com/golang/go/wiki/CompilerOptimizations#func... They do improve the compiler every release, so we might see some of those operations get inlined in the future. More information there: https://github.com/golang/go/blob/master/src/cmd/compile/internal/gc/inl.go#L10 https://github.com/golang/go/blob/master/src/cmd/compile/int...