[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: Yang Guo <yangguo@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Auto-Submit: Simon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61996}
This commit is contained in:
Simon Zünd 2019-06-05 12:52:55 +02:00 committed by Commit Bot
parent 2911a16fa6
commit 3fcbfdaa92
2 changed files with 15 additions and 16 deletions

View File

@ -547,16 +547,12 @@ void AppendFileLocation(Isolate* isolate, StackFrameBase* call_site,
int line_number = call_site->GetLineNumber();
if (line_number != StackFrameBase::kNone) {
builder->AppendCharacter(':');
Handle<String> line_string = isolate->factory()->NumberToString(
handle(Smi::FromInt(line_number), isolate), isolate);
builder->AppendString(line_string);
builder->AppendInt(line_number);
int column_number = call_site->GetColumnNumber();
if (column_number != StackFrameBase::kNone) {
builder->AppendCharacter(':');
Handle<String> column_string = isolate->factory()->NumberToString(
handle(Smi::FromInt(column_number), isolate), isolate);
builder->AppendString(column_string);
builder->AppendInt(column_number);
}
}
}
@ -656,9 +652,7 @@ void JSStackFrame::ToString(IncrementalStringBuilder& builder) {
// For `Promise.all(iterable)` frames we interpret the {offset_}
// as the element index into `iterable` where the error occurred.
builder.AppendCString("Promise.all (index ");
Handle<String> index_string = isolate_->factory()->NumberToString(
handle(Smi::FromInt(offset_), isolate_), isolate_);
builder.AppendString(index_string);
builder.AppendInt(offset_);
builder.AppendCString(")");
return;
}
@ -771,13 +765,10 @@ void WasmStackFrame::ToString(IncrementalStringBuilder& builder) {
}
builder.AppendCString("wasm-function[");
char buffer[16];
SNPrintF(ArrayVector(buffer), "%u]", wasm_func_index_);
builder.AppendCString(buffer);
SNPrintF(ArrayVector(buffer), ":%d", GetPosition());
builder.AppendCString(buffer);
DCHECK(wasm_func_index_ <= kMaxInt);
builder.AppendInt(static_cast<int>(wasm_func_index_));
builder.AppendCString("]:");
builder.AppendInt(GetPosition());
if (has_name) builder.AppendCString(")");

View File

@ -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) {
return part_length_ - current_index_ > length;
}
@ -280,6 +287,7 @@ class IncrementalStringBuilder {
static const int kInitialPartLength = 32;
static const int kMaxPartLength = 16 * 1024;
static const int kPartLengthGrowthFactor = 2;
static const int kIntToCStringBufferSize = 100;
Isolate* isolate_;
String::Encoding encoding_;