-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
errors.Is and errors.As overhead on hot path #5551
Comments
This is the benchstat for the whole of prometheus:
With As a something relative, I've also tried benchmarks with only both syntaxes: package main
import (
"errors"
"testing"
)
func BenchmarkErrorIs(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()
err := errors.New("test")
err2 := errors.New("test2")
for i := 0; i < b.N; i++ {
//errors.Is(err, err2)
_ = (err == err2)
}
}
Again, So there does seem to be a difference, with ~7ns for |
Then, I assume |
Have you checked the performance overhead? While I have nothing against using
errors.Is
anderrors.As
in general I am a uncertain if we should use it here (it looks like a hot path and we control the result ofc.scopeInfo
). As far as I remembererrors.Is
uses some kind of reflection (internal/reflectlight
).CC @dashpole
Originally posted by @pellared in #5535 (comment)
The text was updated successfully, but these errors were encountered: