Skip to content

Commit

Permalink
errors: improve performance of New
Browse files Browse the repository at this point in the history
See Issue golang#29382 and Issue golang#30468.

Improvements in this CL:

name                     old time/op  new time/op  delta
New-8                     352ns ± 2%   225ns ± 5%  -36.04%  (p=0.008 n=5+5)

Improvements together with moving to 1 uintptr:

name                     old time/op  new time/op  delta
New-8                     475ns ± 3%   225ns ± 5%  -52.59%  (p=0.008 n=5+5)

Change-Id: I9d69a14e5e10a6498767defb7d5f26ceedcf9ba5
Reviewed-on: https://go-review.googlesource.com/c/go/+/167401
Run-TryBot: Marcel van Lohuizen <mpvl@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
  • Loading branch information
mpvl committed Mar 14, 2019
1 parent 5402854 commit 8bf18b5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
// Package errors implements functions to manipulate errors.
package errors

import "runtime"

// New returns an error that formats as the given text.
//
// The returned error contains a Frame set to the caller's location and
// implements Formatter to show this information when printed with details.
func New(text string) error {
return &errorString{text, Caller(1)}
// Inline call to errors.Callers to improve performance.
var s Frame
runtime.Callers(2, s.frames[:])
return &errorString{text, s}
}

// errorString is a trivial implementation of error.
Expand Down

0 comments on commit 8bf18b5

Please sign in to comment.