Slow performance of new Error object in modern Node.js

There are cases when it is necessary to update the Error object in order to obtain a stack trace, for example, for logging engines or built-in debugging.

In modern node.js, there is a severe performance hit when an Error object is first created or smart V8 developers decided to spin the stack on demand only when the developer calls the <Error> .stack property.

From my learning of tools, I think that stack trace unwinding is not performed until <Error> .stack is accessed, and this seems like a common sense approach.

Can anyone shed some light on this or suggest ways to test for short debugging of your own V8 code?

+4
source share
1 answer

I built a test case and posted it in my github repository . The results of my tests confirm that the V8 engine, located behind node.js, captures stack information at the time of creation of any Error objects, including subclasses of Error.

My test is quite complicated, but I wanted me to bypass any optimizations in V8 to expand the call stack. I implemented this by creating a random call stack at each test iteration. I also experimented with calling Error.stack and did not call Error.stack, and the effect of this was negligible.

, , 10 , 87 . 21 .

V8 Github Stack Trace API:

, prepareStackTrace (, ()).

+6

Source: https://habr.com/ru/post/1628057/


All Articles