cmd/compile: suboptimal cloning/optimization in slices.Clone #53643
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsDecision
Feedback is required from experts, contributors, and/or the community before a change can be made.
Performance
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes with
go version devel go1.19-d3ffff2790 Tue Jun 28 13:01:41 2022 +0000 linux/amd64
.What operating system and processor architecture are you using (
go env
)?go env
OutputDiscoveries / Proposal
slices.Clone
is currently defined as:append
here seems to be optimized to output what is essentiallymake
+copy
. But if we do that explicitly:and benchmark it (see https://go.dev/play/p/WHvD0zJ33S1) then the new function generally performs better:
Looking at the assembly, it seems that the current version uses
runtime.growslice
while the new one,runtime.mallocgc
. There are other changes in the assembly as well.The text was updated successfully, but these errors were encountered: