-
-
Notifications
You must be signed in to change notification settings - Fork 769
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
Sinon stub with an object and a property has low performance. #1627
Comments
Whoa! 0.2 seconds! Can you make a reproducible test case for us that demonstrates this? I have never been close to anything like that. More like 0.02ms. Maybe you have an enourmous stack depth or something? It doesn't look like it, but ... |
Interesting issue! |
The slowness seems to come from accessing the .stack property on the error, as v8 seems to go through considerable trouble in order to convert it from its internal representation to the string version it uses to report errors. IMO the best fix for this would be to change the line to method.errorForStackTrace = new Error("Stack Trace for original"), and only access the .stack property if an error needs to be reported. Here is a demonstration: |
Ok, if I find time (haha) I'll try to reproduce this. Hoping for someone else to do it though, along with an automatic test for pre/post performance. We could increase the stack depth easily through recursion, say 65000 times, in such a test case. |
Access the .stack property if an error needs to be reported.
This has been fixed by #1671 and published as |
Access the .stack property if an error needs to be reported.
Sinon stub with an object and a property name has low performance due to new Error in the wrap-method.js.
When I create stub with sandbox.stub and pass an object and a property name, it reach this line in the wrap-method.js:
method.stackTrace = (new Error("Stack Trace for original")).stack;
https://github.com/sinonjs/sinon/blob/master/lib/sinon/util/core/wrap-method.js#L110
This line takes about 0.2-0.3 second, therefore my tests runs for 6 minutes.
If I comment it out, it runs for 7 seconds (instead of 6 minutes).
The text was updated successfully, but these errors were encountered: