-
Notifications
You must be signed in to change notification settings - Fork 1.5k
perf: fmt.Errorf used instead of errors.New #9749
Copy link
Copy link
Closed
Labels
priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Metadata
Metadata
Assignees
Labels
priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Throughout the whole codebase there are many places that use
fmt.Errorfwhereaserrors.Newcan be used. Usingfmt.Errorfis roughly 4x slower thanerrors.New.This can be easily benchmarked with:
On my computer I'm getting:
This performance issue can be automatically fixed with:
Those error paths usually aren't hot paths, however it might impact the size of code generated.