This repository has been archived by the owner on Dec 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 689
Allow disabling of stack traces #124
Comments
I want to be clear about this, especially after telling you to raise an
issue. Basically if you had raised the issue first I would have told you
not to write this code. Sorry for wasting your time.
I'm sorry but I don't want to add this feature. Stack traces are the reason
this package exists, if they are disabled there is no reason to use this
package.
…On Wed, Jul 5, 2017 at 4:04 PM, Miki Tebeka ***@***.***> wrote:
Adding of stack traces have performance penalty. In #123
<#123> I show a little benchmark on
performance with or without stack traces. Repeating it here below.
I know that usually errors are not in the critical path of performance,
but sometime they do and I'm working on very performance oriented project
right now, every ns counts :)
err_test.go
package main
import (
"fmt"
"testing"
"github.com/pkg/errors"
)
var err1 = errors.New("hi")
func pkgError(err error, i int) error {
return errors.Wrapf(err, "error number %d", i)
}
func fmtError(err error, i int) error {
return fmt.Errorf("error number %d (%s)", i, err)
}
func BenchmarkPkg(b *testing.B) {
for i := 0; i < b.N; i++ {
pkgError(err1, i)
}
}
func BenchmarkFmt(b *testing.B) {
for i := 0; i < b.N; i++ {
fmtError(err1, i)
}
}
func BenchmarkPkgNoStack(b *testing.B) {
errors.AddStack(false)
defer errors.AddStack(true)
for i := 0; i < b.N; i++ {
pkgError(err1, i)
}
}
Results
$ go test -bench . /tmp/err_test.go
BenchmarkPkg-4 1000000 1090 ns/op
BenchmarkFmt-4 5000000 323 ns/op
BenchmarkPkgNoStack-4 10000000 212 ns/op
PASS
ok command-line-arguments 5.386s
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#124>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAcAyLtHIIOEsYBVec6OJ_C4-bTbj1uks5sKyeAgaJpZM4ON5Ex>
.
|
No worries, just an idea. Thanks for considering this. BTW: I don't think stack traces are the only reason for this. The chaining of errors is highly value by itself. |
If you don't want an error with a stack trace, use the stdlib fmt or errors package. If you want to wrap an error without collecting a stack, use |
So I guess I'm just missing |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Adding of stack traces have performance penalty. In #123 I show a little benchmark on performance with or without stack traces. Repeating it here below.
I know that usually errors are not in the critical path of performance, but sometime they do and I'm working on very performance oriented project right now, every ns counts :)
err_test.go
Results
The text was updated successfully, but these errors were encountered: