Skip to content

cmd/compile: devirtualization of interface calls with type assertions #64824

@mateusz834

Description

Consider:

h := sha256.New() // escapes to heap
h.(encoding.BinaryUnmarshaler).UnmarshalBinary(d) // not devirtualized
h.Write(d) // devirtualized

https://go.dev/play/p/JYPsrebi5Z5

h escapes to heap, because the compiler does not take the opportunity to devirtualize the UnmarshalBinary call.

Same thing happens with even a simpler case (hash.Hash always implements io.Writer)

h := sha256.New()
h.Write(d) // devirtualized
h.(io.Writer).Write(d) // not devirtualized

Activity

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

Metadata

Labels

FeatureRequestIssues asking for a new feature that does not need a proposal.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions