Stack traces are built by storing back-references to the JS functions
on the stack. The human-readable stack trace is computed lazily. The
longer the stack trace, the bigger the chance you retain code objects
beyond their natural lifetime (i.e., introduce memory leaks) but that
might be offset by the observation that the bottom of the stack is
often invariant.
You'll also pay a little in CPU time in the stack frame walker but
that's probably tolerable. I assume you're asking this in the context
of VS Code where human perception is the important factor.