1. 10
  1. 1

    So, the idea is that, for every type (struct, etc), a comparison function is generated, which takes up space in the binary. This function isn’t generated if the type is not comparable, so by strategically inserting zero-length incomparable members into structs, the generation of these functions can be omitted.

    However, wouldn’t something like link-time optimisation be a much better solution to this problem (the idea being that if these comparison functions are never used, they needn’t be linked into the binary in the first place, at least that’s how I understand LTO)?

    1. 2

      Go makes pretty broad use of reflection due to interfaces. A function like reflect.MethodByName(string) lets you call these equality functions in a way the linker can’t see. Reflection generally doesn’t play well with dead code stripping, unfortunately.

      Edit: note that 1.15 should improve this somewhat by allowing dead code like this to be stripped if it’s never converted to an interface (and thus ineligible for reflection).