Speed up StackTraceFrame::GetScriptId()

This retrieves script name directly from StackFrameBase, bypassing
building of StackFrameInfo if one hasn't already been initialized,
thus avoiding computation of expensive properties that are not
required. This matches current behavior of GetScriptNameOrSourceURL()
and is a workaround until a dedicated API is available.

Bug: chromium:1098530
Change-Id: I181dc7feeebaf2f45758bbd29be24ab036e44b19
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2261736
Reviewed-by: Simon Zünd <szuend@chromium.org>
Commit-Queue: Alex Turner <alexmt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68543}
This commit is contained in:
Alex Turner 2020-06-23 19:43:02 -04:00 committed by Commit Bot
parent 0895c903ce
commit 76e9ddb8f5

View File

@ -42,7 +42,21 @@ int StackTraceFrame::GetOneBasedColumnNumber(Handle<StackTraceFrame> frame) {
// static
int StackTraceFrame::GetScriptId(Handle<StackTraceFrame> frame) {
int id = GetFrameInfo(frame)->script_id();
Isolate* isolate = frame->GetIsolate();
// Use FrameInfo if it's already there, but avoid initializing it for just
// the script id, as it is much more expensive than just getting this
// directly. See GetScriptNameOrSourceUrl() for more detail.
int id;
if (!frame->frame_info().IsUndefined()) {
id = GetFrameInfo(frame)->script_id();
} else {
FrameArrayIterator it(
isolate, handle(FrameArray::cast(frame->frame_array()), isolate),
frame->frame_index());
DCHECK(it.HasFrame());
id = it.Frame()->GetScriptId();
}
return id != StackFrameBase::kNone ? id : Message::kNoScriptIdInfo;
}