-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Open
Labels
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Milestone
Description
Go version
Go 1.22
What did you do?
return make([]struct{}, 123) compiles to a call to runtime.makeslice:
LEAQ type:struct {}(SB), AX
MOVL $123, BX
MOVQ BX, CX
PCDATA $1, $0
NOP
CALL runtime.makeslice(SB)
MOVL $123, BX
MOVQ BX, CX
ADDQ $24, SP
POPQ BP
RET
We see this show up in profiles (small, but non-zero) for calls to https://pkg.go.dev/tailscale.com/types/views#Slice.LenIter (which predates Go 1.22's range-over-int):
// LenIter returns a slice the same length as the v.Len().
// The caller can then range over it to get the valid indexes.
// It does not allocate.
func (v Slice[T]) LenIter() []struct{} { return make([]struct{}, len(v.ж)) }I realize that the compiler could omit those makeslice calls when the width of the type being made is zero (as there's no actual allocation).
The compiler already does that when the slice length is zero:
// Recognise make([]T, 0) and replace it with a pointer to the zerobase
(StaticLECall {callAux} _ (Const(64|32) [0]) (Const(64|32) [0]) mem)
&& isSameCall(callAux, "runtime.makeslice")
=> (MakeResult (Addr <v.Type.FieldType(0)> {ir.Syms.Zerobase} (SB)) mem)
/cc @golang/compiler @twitchyliquid64 @maisem
Jorropo
Metadata
Metadata
Assignees
Labels
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Type
Projects
Status
Todo