Open Jorropo opened 5 months ago
Similar Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
AFAIK the old inliner were hardcoded to attribute a cost of 1 for cheap calls to , this sounds better to me as it's usual to make many calls back to back on the same buffer and aware users prove bound checks ahead of time.
Usually like this:binary.*Endian.Uint*
and friends as well as always inline theses when possible
_ = b[:32]
a := binary.LittleEndian.Uint64(b)
a := binary.LittleEndian.Uint64(b[8:])
a := binary.LittleEndian.Uint64(b[16:])
a := binary.LittleEndian.Uint64(b[24:])
cc @golang/compiler
Well actually, I tried go1.21.11
and it has the same issues.
It's fixed by changing cmd/compile/internal/inline/inl.go:inlineBigFunctionMaxCost
to 80
, so I'd say your presumption is correct, the function is large enough that we were forced to turn inlining way down.
I'm not sure what, if anything, could be done here. We do need to defend against making functions arbitrarily larger by inlining too much. If we could know with some certainty that inlining would make things smaller, then it would be ok. (We do inline your u64
under that rule.) Unfortunately at inlining time littleEndian.Uint64
's body looks kind of big, only after lots of optimization work do we realize it is only a bounds check + a load.
@thanm @mdempsky for ideas.
Hmm, we do treat littleEndian.Uint64
specially in the inliner as far as cost goes (See https://go-review.googlesource.com/c/go/+/349931). So maybe these inlinings should still happen?
I was about to say, if we have a list of hardcoded "cheap" functions we should also inline theses.
Go version
go version devel go1.23-4f77a83589 Tue Jun 18 22:25:08 2024 +0000 linux/amd64
go version 1.22.4
go version 1.21.11
Output of
go env
in your module/workspace:What did you do?
Sorry for the huge reproducer, I couldn't minize well, I guess this has something to do with the caller aware inliner making poor decisions due to the function being huge.
What did you see happen?
What did you expect to see?
I expect to see raw
MOVQ
andMOVL
foru64
andu32
functions. Note: the bounds check would be proven at compile time, making a call strictly inferior as there are no panic index branch frombinary.*
.