Error should compute .stack and friends lazily
authorfpizlo@apple.com <fpizlo@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 10 Sep 2017 19:00:03 +0000 (19:00 +0000)
committerfpizlo@apple.com <fpizlo@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 10 Sep 2017 19:00:03 +0000 (19:00 +0000)
commit878fa083d18f4a7eb093d489e5f14ed2c2ae1c08
tree97536c613c403a005b06fd96305f35b6ae9e06bc
parent5037e77da3393d46fc86a1ebc3cc4272931fe88b
Error should compute .stack and friends lazily
https://bugs.webkit.org/show_bug.cgi?id=176645

Reviewed by Saam Barati.
JSTests:

* ChakraCore.yaml: Skip test that was testing non-standard behavior of these fields.
* microbenchmarks/new-error.js: Added.
* microbenchmarks/throw.js: Added.

Source/JavaScriptCore:

Building the string portion of the stack trace after we walk the stack accounts for most of
the cost of computing the .stack property. So, this patch makes ErrorInstance hold onto the
Vector<StackFrame> so that it can build the string only once it's really needed.

This is an enormous speed-up for programs that allocate and throw exceptions.

It's a 5.6x speed-up for "new Error()" with a stack that is 4 functions deep.

It's a 2.2x speed-up for throwing and catching an Error.

It's a 1.17x speed-up for the WSL test suite (which throws a lot).

It's a significant speed-up on many of our existing try-catch microbenchmarks. For example,
delta-blue-try-catch is 1.16x faster.

* interpreter/Interpreter.cpp:
(JSC::GetStackTraceFunctor::GetStackTraceFunctor):
(JSC::GetStackTraceFunctor::operator() const):
(JSC::Interpreter::getStackTrace):
* interpreter/Interpreter.h:
* runtime/Error.cpp:
(JSC::getStackTrace):
(JSC::getBytecodeOffset):
(JSC::addErrorInfo):
(JSC::addErrorInfoAndGetBytecodeOffset): Deleted.
* runtime/Error.h:
* runtime/ErrorInstance.cpp:
(JSC::ErrorInstance::ErrorInstance):
(JSC::ErrorInstance::finishCreation):
(JSC::ErrorInstance::materializeErrorInfoIfNeeded):
(JSC::ErrorInstance::visitChildren):
(JSC::ErrorInstance::getOwnPropertySlot):
(JSC::ErrorInstance::getOwnNonIndexPropertyNames):
(JSC::ErrorInstance::defineOwnProperty):
(JSC::ErrorInstance::put):
(JSC::ErrorInstance::deleteProperty):
* runtime/ErrorInstance.h:
* runtime/Exception.cpp:
(JSC::Exception::visitChildren):
(JSC::Exception::finishCreation):
* runtime/Exception.h:
* runtime/StackFrame.cpp:
(JSC::StackFrame::visitChildren):
* runtime/StackFrame.h:
(JSC::StackFrame::StackFrame):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221836 268f45cc-cd09-0410-ab3c-d52691b4dbfc
17 files changed:
JSTests/ChakraCore.yaml
JSTests/ChangeLog
JSTests/microbenchmarks/new-error.js [new file with mode: 0644]
JSTests/microbenchmarks/throw.js [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/ScriptCallStack.cpp
Source/JavaScriptCore/inspector/ScriptCallStackFactory.cpp
Source/JavaScriptCore/interpreter/Interpreter.cpp
Source/JavaScriptCore/interpreter/Interpreter.h
Source/JavaScriptCore/runtime/Error.cpp
Source/JavaScriptCore/runtime/Error.h
Source/JavaScriptCore/runtime/ErrorInstance.cpp
Source/JavaScriptCore/runtime/ErrorInstance.h
Source/JavaScriptCore/runtime/Exception.cpp
Source/JavaScriptCore/runtime/Exception.h
Source/JavaScriptCore/runtime/StackFrame.cpp
Source/JavaScriptCore/runtime/StackFrame.h