cmd/compile: avoid updating capacity if unused #23832
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsFix
The path to resolution is known, but the work has not been done.
Performance
Milestone
Using go1.10,
Consider the following code:
The compiled assembly is as follows:
You'll notice that the slice header {ptr, len, cap} are loaded into {DX, AX, CX}. Several times in the assembly, you see the CX register being used as it seems that
b = b[8:]
on line 17 causes the capacity to also be updated.However, the go code actually does not care about the capacity at all. If the compiler is able to prove that the capacity will never be used, then it could avoid doing the math to ensure that the capacity is up-to-date.
\cc @randall77 @dr2chase
The text was updated successfully, but these errors were encountered: