Commit b818b458 authored by Josh Karlin's avatar Josh Karlin Committed by Commit Bot

Optimize SourceLocation::Capture

Determining the v8::Isolate can take ~25% of the time
required to capture the top of the stack. This CL gets the Isolate
from the ExecutionContext when it's available to speed things up.

Bug: 851531
Change-Id: Ia823fbb0643c62f1a4da3cc289b23ca6fb43da2b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2122568
Commit-Queue: Josh Karlin <jkarlin@chromium.org>
Reviewed-by: default avatarNate Chapin <japhet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754054}
parent 8fe86e69
......@@ -23,15 +23,17 @@ namespace blink {
namespace {
std::unique_ptr<v8_inspector::V8StackTrace> CaptureStackTrace(bool full) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
std::unique_ptr<v8_inspector::V8StackTrace> CaptureStackTrace(
v8::Isolate* isolate,
bool full) {
ThreadDebugger* debugger = ThreadDebugger::From(isolate);
if (!debugger || !isolate->InContext())
return nullptr;
ScriptForbiddenScope::AllowUserAgentScript allow_scripting;
return debugger->GetV8Inspector()->captureStackTrace(full);
}
}
} // namespace
// static
std::unique_ptr<SourceLocation> SourceLocation::Capture(
......@@ -39,7 +41,7 @@ std::unique_ptr<SourceLocation> SourceLocation::Capture(
unsigned line_number,
unsigned column_number) {
std::unique_ptr<v8_inspector::V8StackTrace> stack_trace =
CaptureStackTrace(false);
CaptureStackTrace(v8::Isolate::GetCurrent(), false);
if (stack_trace && !stack_trace->isEmpty())
return SourceLocation::CreateFromNonEmptyV8StackTrace(
std::move(stack_trace), 0);
......@@ -50,8 +52,14 @@ std::unique_ptr<SourceLocation> SourceLocation::Capture(
// static
std::unique_ptr<SourceLocation> SourceLocation::Capture(
ExecutionContext* execution_context) {
// v8::Isolate::GetCurrent is slow so get it from the ExecutionContext when
// available.
// TODO(jkarlin): Force all callers of all Capture() methods to call with a
// valid ExecutionContext.
v8::Isolate* isolate = execution_context ? execution_context->GetIsolate()
: v8::Isolate::GetCurrent();
std::unique_ptr<v8_inspector::V8StackTrace> stack_trace =
CaptureStackTrace(false);
CaptureStackTrace(isolate, false);
if (stack_trace && !stack_trace->isEmpty())
return SourceLocation::CreateFromNonEmptyV8StackTrace(
std::move(stack_trace), 0);
......@@ -137,7 +145,7 @@ std::unique_ptr<SourceLocation> SourceLocation::FromFunction(
// static
std::unique_ptr<SourceLocation> SourceLocation::CaptureWithFullStackTrace() {
std::unique_ptr<v8_inspector::V8StackTrace> stack_trace =
CaptureStackTrace(true);
CaptureStackTrace(v8::Isolate::GetCurrent(), true);
if (stack_trace && !stack_trace->isEmpty())
return SourceLocation::CreateFromNonEmptyV8StackTrace(
std::move(stack_trace), 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment