-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
perf(errors/gerror): 缓存堆栈信息 #4071
base: master
Are you sure you want to change the base?
Conversation
// You can obtain one at https://github.com/gogf/gf. | ||
|
||
package gerror_test | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个文件稍后会删掉
这块是
由于 |
This is the noise reduction process specially done by the error handling component of
Since |
这样还是有影响的吧,只能看到是两个错误,然后是堆栈信息,但是并不知道哪个错误的堆栈在哪里,还得一个个看
不能认同
大概思路就是使用先前保存的pc指针,也就是每一层调用栈函数的pc的指针,
其实这次pr的想法是我看到了一篇文章,里面介绍了可以把堆栈的一些信息给保存起来,再次使用的时候,不需要再次调用runtime库获取,我在本地实现了一下,代码其实也不多,就四五十行左右(本地那版实现比现在的性能还要高出两倍),我就想尝试在gerror看能不能实现下,目前来说,可以实现的和先前的效果一模一样,没什么难度 |
This still has an impact. I can only see two errors and then the stack information, but I don’t know where the stack of which error is. I have to look at it one by one.
Can't agree
The general idea is to use the previously saved pc pointer, which is the pc pointer of the call stack function at each layer.
In fact, the idea for this PR was that I saw an article that introduced how to save some information on the stack. When using it again, there is no need to call the runtime library again to obtain it. I implemented it locally, and the code is actually the same. Not much, just about forty or fifty lines (the local version is twice as fast as the current one), so I want to try it in gerror to see if it can be implemented. At present, the effect that can be achieved is exactly the same as the previous one. , no difficulty |
建议搞一个 glog 的改造,这个使用的地方更多 |
It is recommended to make a transformation of glog, which can be used in more places. |
好想法 |
good idea |
@wln32 堆栈降噪那个是很有必要的,因为 |
@wln32 Stack noise reduction is very necessary, because the new |
为gerror缓存堆栈信息,缓存之后,性能提升几倍,内存申请也减少了许多,不过目前仍有一些问题与主分支的代码输出的结果不同,
gerror类型使用Wrap再次包装之后,再次输出的时候,两个错误的堆栈信息合并到一起了,这样看起来能够大幅度减少一些噪音,但似乎Wrap之后的error堆栈信息丢失了,只能看到一个“gerror/Wrap包装数据3”错误信息,这样是否不妥?
我使用"github.com/pkg/errors"这个包,使用相同的逻辑,使用errors.New,然后在Test3函数重新使用errors.Wrap包装一下,再次返回,输出的结果也是两次堆栈信息都是独立输出的,并没有合并到一起去
此外本次提交的代码没有忽略标准库的路径还有编译器自动生成的代码路径
gf的输出结果为
此次pr的输出结果
性能比对
分为直接用new返回,中间不做任何处理,还有一个是中间用Wrap包装了下new返回的error
都使用%+v解开堆栈信息来测试
当前主分支的new
当前主分支的wrap
当前pr的new
当前pr的wrap