golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.48k stars 17.59k forks source link

cmd/compile: deduplicate alg and noalg type descriptors to allow binary space optimizations #47904

Open martisch opened 3 years ago

martisch commented 3 years ago

The compiler supports SetNoAlg on types. This brings binary space savings by not needing to generate equality functions for those types. Applying this setting to backing arrays of slices (#32595) and maps (#47068) has introduced bugs into go binaries in the past because values of types that should be equal didnt compare equal as internally they were different types.

The general fix and even better space saving impact would be to have the compiler/linker deduplicate noalg with alg type descriptors giving preference to alg descriptors that link algorithms. See discussion with @mdempsky https://github.com/golang/go/issues/47068#issuecomment-875859035

Alternatively the compiler and linker combination could be smart enough to understand if algs can ever be used because the type is never exposed directly to user code. While this is more general and automatic, it would be more complex and require more work during compilation/linking instead of annotating the places where it is the case manually using SetNoAlg in the compiler.

Once this is ready we can save binary space by:

/cc @mdempsky @cherrymui @randall77

gopherbot commented 3 years ago

Change https://golang.org/cl/344349 mentions this issue: cmd/compile: mark type of pointer to noalg type noalg too