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: specialize variadic functions #29085

Open
josharian opened this Issue Dec 3, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@josharian
Contributor

josharian commented Dec 3, 2018

This is an idea for a compiler optimization to explore. I don't know whether it'll yield worthwhile fruit.

We can generate multiple forms of variadic functions. For example, given:

func f(s ...int) {
  // body
}

We could also generate and compile:

func f.0() {
  s := nil
  // body
}

func f.1(x int) {
  s := []int{x}
  // body
}

This would shrink call sites. And hopefully the compiler would be able to use the info about s to compile f.0 and f.1 more aggressively. (We might need to add an optimization to remove loops when the loop iteration count is known to be 1.)

There are plenty of open questions. For example: how to decide which variants to generate, whether to rewrite .N suffixes away in backtraces, where to record info about which variants got generated, what the impact is on inlining and escape analysis.

This would also serve as a useful experiment for generics, in that we would need to sort out some questions about how to generate specialized variants of a particular function.

@josharian josharian added this to the Unplanned milestone Dec 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment