-
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
Basic blocks, which return non-nil errors, are usually executed rarely. So it would great from performance perspective to move them to the end of assembly output. This should provide the following benefits:
- This will remove unnecessary jumps over rarely executed basic blocks.
- This will make frequently executed code more compact.
- This should reduce pressure on CPU instruction cache and may improve performance for the executed code.
The following heuristics can be used for determining whether the basic block returns non-nil error:
- The block is located in the function, which returns
error. The function may return multiple results. If at least a single returned result iserror, then it is good idea to look closer to basic blocks of this function. - The last statement in the basic block is
return, which returns non-nilerror. If some globally definederroris returned, then assume it is non-nil. If some function is called at the place oferrorreturn result, then assume it returns non-nil error in the following cases:- If this is a well-known function from standard library, which returns errors, such as
fmt.Errorf()orerrors.New(). - If the function accepts at least a single non-nil
errorargument. This should cover common idiom:if err != nil { return someErrorWrapper(args, err) }.
- If this is a well-known function from standard library, which returns errors, such as
I verified these heuristics are missing in Go1.21.
CAFxX, bwplotka, caozhuozi, sten4eg, franchb and 2 more
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