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
Metadata
Assignees
Labels
Type
Projects
Status
Todo
Activity