-
Couldn't load subscription status.
- Fork 18.4k
Closed
Labels
ImplementationIssues describing a semantics-preserving change to the Go implementation.Issues describing a semantics-preserving change to the Go implementation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performance
Description
Go version
go version go1.25.1 darwin/amd64
Output of go env in your module/workspace:
N/AWhat did you do?
I ran
go build -gcflags '-m=2' . 2>&1 | grep 'can inline'on a package consisting of the following file:
package p
var a, b []int
func NoIndices() {
b = a[:]
}
func LowIndex() {
b = a[0:]
}
func HighIndex() {
b = a[:len(a)]
}
func BothIndices() {
b = a[0:len(a)]
}What did you see happen?
Superfluous indices in slice expressions contribute to the enclosing function's inlining cost.
./p.go:5:6: can inline NoIndices with cost 4 as: func() { b = a[:] }
./p.go:9:6: can inline LowIndex with cost 5 as: func() { b = a[0:] }
./p.go:13:6: can inline HighIndex with cost 6 as: func() { b = a[:len(a)] }
./p.go:17:6: can inline BothIndices with cost 7 as: func() { b = a[0:len(a)] }
What did you expect to see?
Superfluous indices in slice expressions do not contribute to the enclosing function's inlining cost:
./p.go:5:6: can inline NoIndices with cost <n> as: func() { b = a[:] }
./p.go:9:6: can inline LowIndex with cost <n> as: func() { b = a[0:] }
./p.go:13:6: can inline HighIndex with cost <n> as: func() { b = a[:len(a)] }
./p.go:17:6: can inline BothIndices with cost <n> as: func() { b = a[0:len(a)] }
See this now abandoned CL, in which dropping a superfluous low index in a slice expression is enough to make path.Base inlineable.
Related: #61502
tmthrgd, samborkent, thediveo and Deleplace
Metadata
Metadata
Assignees
Labels
ImplementationIssues describing a semantics-preserving change to the Go implementation.Issues describing a semantics-preserving change to the Go implementation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performance