-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Improve stack overflow stack trace pretty print #122243
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
base: main
Are you sure you want to change the base?
Improve stack overflow stack trace pretty print #122243
Conversation
The current algorithm used for the stack overflow stactrace pretty printing isn't able to find repetitions that don't start at the first frame. That leads to huge stack traces when there are few non-repeated frames on the top of the stack, e.g. when a recursion in managed method calls to some common chain of methods and the stack overflow occurs down that chain and not in the recursive part. This change fixes that. When no repeated sequence is found at the top of the stack, it tries to search from the next frame and so on until a repeated sequence is identified. Close dotnet#118218
|
With this change, the stack trace from the test code from #118218 looks like this: |
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.
Pull request overview
This PR improves the stack overflow stack trace pretty printing algorithm to detect repetitions that don't start at the first frame. Previously, the algorithm could only identify repeated sequences starting from the top of the stack, leading to excessively long stack traces when non-repeated frames appeared at the beginning.
Key changes:
- Refactored repetition detection from inline (during stack walk) to post-processing analysis
- Removed member variables (
m_commonStartIndex,m_largestCommonStartLength,m_largestCommonStartRepeat) in favor of local variables inPrintStackTrace - Implemented nested loop algorithm that searches for repeated sequences starting from different offsets in the stack
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| largestCommonLength = 0; | ||
| largestCommonRepeat = 0; | ||
|
|
||
| for (int i = largestCommonStartOffset; i < m_frames.Count(); i++) |
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 looks like a quadratic algorithm. What's the worst-case delay that it can lead to in real-world apps?
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.
I believe there are O(N log N) algorithms to do this if this one is too slow.
The current algorithm used for the stack overflow stactrace pretty printing isn't able to find repetitions that don't start at the first frame. That leads to huge stack traces when there are few non-repeated frames on the top of the stack, e.g. when a recursion in managed method calls to some common chain of methods and the stack overflow occurs down that chain and not in the recursive part.
This change fixes that. When no repeated sequence is found at the top of the stack, it tries to search from the next frame and so on until a repeated sequence is identified.
Close #118218