Proposals Unofficial Go proposal tracker

Add Same function to report whether two maps are identical

#78456 · maps · low impact · Accepted ·

Go maps are references to hash tables, but the language has no direct way to check whether two map values refer to the same table. Maps are not comparable with ==, and the workaround of comparing pointers via reflect is slow and awkward. Knowing that two maps alias is useful, for example to take a shortcut in a set union.

The new maps.Same function reports whether two maps refer to the same data structure. The two maps may have different named types, but they must share the same key and value types. The call compiles down to a single pointer comparison.

func union(x, y map[string]bool) map[string]bool {
    if maps.Same(x, y) {
        return x
    }
    z := maps.Clone(x)
    maps.Copy(z, y)
    return z
}
Proposal
#78456 by adonovan
Status
Accepted on Jul 8, 2026
Impact
low
Area
maps