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: notice when function variables are never reassigned, avoid indirect calls #42569

bradfitz opened this issue Nov 12, 2020 · 0 comments


Copy link

@bradfitz bradfitz commented Nov 12, 2020

It's somewhat common for people to have package-level variables like:

var u64 = binary.BigEndian.Uint64

So later in their code they can just write u64(buf[8:]) many times without stuttering a loud binary.BigEndian.Uint64 etc all over the page.

But calling via such a func variable is ~7.5x slower than calling binary.BigEndian.Uint64 directly:

It'd be nice if the compiler noticed that the u64 variable was only initialized once and never reassigned to and never had its address taken (so it can't be mutated elsewhere), and did the fast thing automatically, not doing the indirect call.

/cc @randall77 @mdempsky @ianlancetaylor @cherrymui @josharian @danderson

@cagedmantis cagedmantis added this to the Backlog milestone Nov 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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