Commit 3fcbfdaa authored by Simon Zünd's avatar Simon Zünd Committed by Commit Bot

[stack-trace] Add AppendInt to IncrementalStringBuilder for numbers

This CL changes the way stack trace serialization appends numbers.
Instead of converting plain int to Handle<String>, they are converted
to char*. The reason is that appending a Handle<String> causes the
IncrementalStringBuilder to shrink the current part and create two
ConsString instances to concatenate the accumulator, the current part and
the passed in Handle<String>.

This CL improves stack trace serialization micro benchmarks by ~12%.

Bug: v8:8742
Change-Id: I174667379084381245827cb979f91db3c59ce75e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1643169
Commit-Queue: Simon Zünd <szuend@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Auto-Submit: Simon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61996}
parent 2911a16f
...@@ -547,16 +547,12 @@ void AppendFileLocation(Isolate* isolate, StackFrameBase* call_site, ...@@ -547,16 +547,12 @@ void AppendFileLocation(Isolate* isolate, StackFrameBase* call_site,
int line_number = call_site->GetLineNumber(); int line_number = call_site->GetLineNumber();
if (line_number != StackFrameBase::kNone) { if (line_number != StackFrameBase::kNone) {
builder->AppendCharacter(':'); builder->AppendCharacter(':');
Handle<String> line_string = isolate->factory()->NumberToString( builder->AppendInt(line_number);
handle(Smi::FromInt(line_number), isolate), isolate);
builder->AppendString(line_string);
int column_number = call_site->GetColumnNumber(); int column_number = call_site->GetColumnNumber();
if (column_number != StackFrameBase::kNone) { if (column_number != StackFrameBase::kNone) {
builder->AppendCharacter(':'); builder->AppendCharacter(':');
Handle<String> column_string = isolate->factory()->NumberToString( builder->AppendInt(column_number);
handle(Smi::FromInt(column_number), isolate), isolate);
builder->AppendString(column_string);
} }
} }
} }
...@@ -656,9 +652,7 @@ void JSStackFrame::ToString(IncrementalStringBuilder& builder) { ...@@ -656,9 +652,7 @@ void JSStackFrame::ToString(IncrementalStringBuilder& builder) {
// For `Promise.all(iterable)` frames we interpret the {offset_} // For `Promise.all(iterable)` frames we interpret the {offset_}
// as the element index into `iterable` where the error occurred. // as the element index into `iterable` where the error occurred.
builder.AppendCString("Promise.all (index "); builder.AppendCString("Promise.all (index ");
Handle<String> index_string = isolate_->factory()->NumberToString( builder.AppendInt(offset_);
handle(Smi::FromInt(offset_), isolate_), isolate_);
builder.AppendString(index_string);
builder.AppendCString(")"); builder.AppendCString(")");
return; return;
} }
...@@ -771,13 +765,10 @@ void WasmStackFrame::ToString(IncrementalStringBuilder& builder) { ...@@ -771,13 +765,10 @@ void WasmStackFrame::ToString(IncrementalStringBuilder& builder) {
} }
builder.AppendCString("wasm-function["); builder.AppendCString("wasm-function[");
DCHECK(wasm_func_index_ <= kMaxInt);
char buffer[16]; builder.AppendInt(static_cast<int>(wasm_func_index_));
SNPrintF(ArrayVector(buffer), "%u]", wasm_func_index_); builder.AppendCString("]:");
builder.AppendCString(buffer); builder.AppendInt(GetPosition());
SNPrintF(ArrayVector(buffer), ":%d", GetPosition());
builder.AppendCString(buffer);
if (has_name) builder.AppendCString(")"); if (has_name) builder.AppendCString(")");
......
...@@ -147,6 +147,13 @@ class IncrementalStringBuilder { ...@@ -147,6 +147,13 @@ class IncrementalStringBuilder {
} }
} }
V8_INLINE void AppendInt(int i) {
char buffer[kIntToCStringBufferSize];
const char* str =
IntToCString(i, Vector<char>(buffer, kIntToCStringBufferSize));
AppendCString(str);
}
V8_INLINE bool CurrentPartCanFit(int length) { V8_INLINE bool CurrentPartCanFit(int length) {
return part_length_ - current_index_ > length; return part_length_ - current_index_ > length;
} }
...@@ -280,6 +287,7 @@ class IncrementalStringBuilder { ...@@ -280,6 +287,7 @@ class IncrementalStringBuilder {
static const int kInitialPartLength = 32; static const int kInitialPartLength = 32;
static const int kMaxPartLength = 16 * 1024; static const int kMaxPartLength = 16 * 1024;
static const int kPartLengthGrowthFactor = 2; static const int kPartLengthGrowthFactor = 2;
static const int kIntToCStringBufferSize = 100;
Isolate* isolate_; Isolate* isolate_;
String::Encoding encoding_; String::Encoding encoding_;
......
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