Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

martisch opened this issue Aug 23, 2021 · 1 comment
binary-size NeedsDecision


Copy link

@martisch martisch commented Aug 23, 2021

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 #47068 (comment)

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

Copy link

@gopherbot gopherbot commented Aug 23, 2021

Change mentions this issue: cmd/compile: mark type of pointer to noalg type noalg too

gopherbot pushed a commit that referenced this issue Aug 23, 2021
Arrays marked noalg are created by the compiler to hold keys and values
to initialize map literals. The ssa backend creates a pointer type for
the array type when creating an OpAddr while processing the loop that
initializes the map from the arrays. The pointer type does not inherit
the noalg property but points to the noalg array type.

This causes values created through reflect of types that should be
equal to compare unequal because the noalg and alg type might be
compared and these are not the same.

A similar problem occurred in #32595 for argument arrays of defer structs.

Created #47904 to track improve noalg handling to be able to
reintroduce this optimization again.

Fixes #47068

Change-Id: I87549342bd404b98d71a3c0f33e3c169e9d4efc8
Trust: Martin Möhrmann <>
Run-TryBot: Martin Möhrmann <>
TryBot-Result: Go Bot <>
Reviewed-by: Cuong Manh Le <>
Reviewed-by: Matthew Dempsky <>
@toothrot toothrot added the NeedsDecision label Aug 24, 2021
@toothrot toothrot added this to the Backlog milestone Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
binary-size NeedsDecision
None yet

No branches or pull requests

3 participants