go-errors / errors

errors with stacktraces for go
https://godoc.org/github.com/go-errors/errors
MIT License
940 stars 93 forks source link

optimize SourceLine to not create a new instance of Error from String method #40

Closed kishoresenji closed 2 years ago

kishoresenji commented 2 years ago

We noticed that ErrorStack() takes a considerable amount of cpu while computing the stack and the time is spent in SourceLine() method returning a New(err). This error is completely ignored in the String() method. The optimization is to give the builtin error instead of Error from an internal method which can be used by the String() method. To keep the backward compatibility, SourceLine() is modified to invoke the internal method sourceLine() and returning an Error.

kishoresenji commented 2 years ago
Screen Shot 2022-01-14 at 2 00 44 PM
ConradIrwin commented 2 years ago

Thanks @kishoresenji

ConradIrwin commented 2 years ago

I've added you as a collaborator to this repo, thank you for the contribution! Please feel free to send pull requests more :)