Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: inlining budget excludes cross-package calls #22194

Closed
mdempsky opened this issue Oct 10, 2017 · 2 comments
Closed

cmd/compile: inlining budget excludes cross-package calls #22194

mdempsky opened this issue Oct 10, 2017 · 2 comments

Comments

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Oct 10, 2017

In the example below, p.G and q.H are identical, except that p.G is in the same package as p.F, yet cmd/compile decides that q.H is inlineable whereas p.G is not.

This is because cmd/compile currently only computes Inlcost for locally defined functions. Calls to functions in external packages are effectively treated as free.

$ go tool compile -m p.go
p.go:3:6: can inline F
p.go:13:3: inlining call to F

$ go tool compile -m q.go
q.go:5:6: can inline H
q.go:6:5: inlining call to p.F

$ cat p.go
package p

func F() {
    print(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    print(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    print(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    print(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    print(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    print(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
}

func G() {
    F()
    print(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    print(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    print(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    print(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    print(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    print(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
}

$ cat q.go
package q

import "./p"

func H() {
    p.F()
    print(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    print(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    print(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    print(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    print(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    print(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
}
@mdempsky mdempsky added the NeedsFix label Oct 10, 2017
@ALTree

This comment has been minimized.

Copy link
Member

@ALTree ALTree commented Oct 10, 2017

This is #19261, see josh comment: #19261 (comment)

@mdempsky

This comment has been minimized.

Copy link
Member Author

@mdempsky mdempsky commented Oct 10, 2017

@ALTree Indeed, thanks! Closing as duplicate.

@mdempsky mdempsky closed this Oct 10, 2017
@golang golang locked and limited conversation to collaborators Oct 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.