cmd/compile: optimize struct reset logic #52373
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
Consider the following:
Performance:
Both snippets are semantically equivalent, but
ResetB
is much faster.However,
ResetA
is common in reset logic where the intention is to reset all fields except a few select fields. This pattern is more maintainable since it properly resets the struct even if new fields are added to it later on.The compiler should recognize the pattern exhibited in
ResetA
and avoid the unnecessary copy ofs.Large = s.Large
.The text was updated successfully, but these errors were encountered: