cmd/compile: unnecessary hash/eq functions for global arrays #30528
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Performance
Milestone
This is a generalization of the problem described in #30449.
Suppose we have a unexported global variable:
and none of the operations performed on this array:
==
or as a map key)For example, operations like indexing (e.g.,
myArray[3]
) and slicing (e.g.,myArray[:]
) are permitted.If the above conditions are met, I believe that hash/eq functions need not be generated for that array since it is provably not used in the package, and cannot be used dynamically since the array itself does not escape from the package.
The use case for this is code like:
We declare
globalMessageTypes
as an array so that theT.Type
andR.Type
methods do not need a bounds check when indexing into the global array. However, the generated hash/eq functions add significant binary bloat.The workaround to this is to use a global slice instead of an array, but that has other issues (see #30529).
The text was updated successfully, but these errors were encountered: