-
-
Notifications
You must be signed in to change notification settings - Fork 32.8k
util: hide duplicated stack frames when using util.inspect #59447
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?
util: hide duplicated stack frames when using util.inspect #59447
Conversation
Long stack traces often have duplicated stack frames from recursive calls. These make it difficult to identify important parts of the stack. This hides the duplicated ones and notifies the user which lines were hidden.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #59447 +/- ##
==========================================
- Coverage 89.88% 89.87% -0.01%
==========================================
Files 656 656
Lines 192947 193266 +319
Branches 37841 37927 +86
==========================================
+ Hits 173427 173699 +272
- Misses 12054 12098 +44
- Partials 7466 7469 +3
🚀 New features to boost your workflow:
|
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.
Wouldn't it be more confusing that a recursive call is not reflected in the stacktrace?
@legendecas it is reflected in form of a comment and the frames are of course kept once. Just the duplicates are removed. |
PTAL |
function getDuplicateErrorFrameRanges(frames) { | ||
// Build a map: frame line -> sorted list of indices where it occurs | ||
const result = []; | ||
const lineToPositions = new Map(); |
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.
these are strings, is Map significantly faster than a null object or SafeMap (or even a $
-key-salted normal object) such that this is the best choice?
} | ||
|
||
// Theoretical maximum range, adjusted while iterating | ||
let range = positions.at(-1) - 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.
let range = positions.at(-1) - i; | |
let range = positions[positions.length - 1] - i; |
i assume this is faster, and avoids the need for a primordial
if (gcdRange !== 0) { | ||
// Add other possible ranges as fallback | ||
extraSteps ??= new Set(); | ||
extraSteps.add(gcdRange); |
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.
similarly, this seems like it could be an object, with ObjectKeys at the end, and it'd be faster than spreading a Set into an array?
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 would be surprised if that's faster, while it will likely not be the major issue (this path is only triggered for some cases and for those, the set / object would contain normally never more than five entries).
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.
If it's not an issue, can we use SafeMap/SafeSet instead?
Long stack traces often have duplicated stack frames from recursive calls. These make it difficult to identify important parts of the stack. This hides the duplicated ones and notifies the user which lines were hidden.
I believe the wording might still be improved, it would be great to get some input about that.