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: PGO devirtualization of partial interface implementations #64673

Open
prattmic opened this issue Dec 12, 2023 · 0 comments
Open
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Performance
Milestone

Comments

@prattmic
Copy link
Member

Callees that only partially implement an interface (they are embedded in another type that completes the interface) cannot be devirtualized.

e.g., consider:

func foo(r io.ReadCloser) {
  b := make([]byte, 64)
  r.Read(b)
}

func main() {
  b := make([]byte, 64)
  r := bytes.NewReader(b)
  rc := io.NopCloser(r)
  foo(rc)
}

io.nopCloser embeds Reader, so the PGO profile will report a call from foo -> bytes.Reader.Read. Devirtualization will consider this candidate, determine that bytes.Reader does not implement io.ReadCloser and decide that it must not be valid, but it is valid because of the wrapper type not visible from the profile.

Devirtualization could be more lenient and only type-check the single method that is called rather than the entire interface, though this risks more false positives in ambiguous situations.

cc @cherrymui @aclements

@prattmic prattmic added Performance NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Dec 12, 2023
@prattmic prattmic added this to the Backlog milestone Dec 12, 2023
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Performance
Projects
Development

No branches or pull requests

2 participants