Skip to content

cmd/compile: avoid convT2E for T = struct{} (empty struct) #18402

@rogpeppe

Description

@rogpeppe

go version devel +0b2daa5 Thu Dec 1 11:23:17 2016 +0000 linux/amd64

An empty struct is held in an interface value as a non-nil pointer. This means that
converting an empty struct to an interface is more expensive that
it needs to be be - it involves a call to convT2E.

Given that conversion of empty structs to interfaces is common (for example,
empty structs are often used as context keys) it may be better to use
the nil pointer as the value part of the interface, making
interface{}(struct{}{}) as efficient as interface{}((*int)(nil)).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions