Open sylr opened 4 years ago
@randall77, I think you've got the title backwards. It looks like the sliced array is outperforming the slice-literal version for some reason.
Sorry, yes.
Slow routine allocates because len(base)+len(fixed) of slices isn't determined at compile time, whereas with arrays the expression is constant.
Or to be more precise, during the escape analysis phase, len(base)+len(fixed)
isn't known to be a constant. (Later on, SSA figures it out.)
So both are optimized to the extent of what they can be or is there room for improvement in the slice case ?
It’s definitely possible for them to be improved. The question—which I can’t answer offhand—is whether it is possible to make a small, local improvement that would cover this case, or whether it would require an overhaul. (There are good independent reasons for an overhaul, but what is needed—eliminating one of the compiler’s intermediate representations—is a huge undertaking.)
Is this a duplicate of #20533?
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
I would have expected
BenchmarkCapNoMagicNumber
andBenchmarkCapNoMagicNumberFixedSlices
to have the same throughput.What did you see instead?