Commit 9b734766 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[json] Remove pretenuring based on json source size

It's not necessarily helpful, and can actually cause pretty bad performance and
memory usage.

I moved up the next_ field to where allocation_ used to be since apparently the
alignment caused by it has huge impact on perf (>10% diff...) at least on my
machine.

Change-Id: I1026a2e954d061b1a178f6a733d8ef81ae6d0cab
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1594432
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61250}
parent b3b6b5c6
...@@ -262,10 +262,6 @@ JsonParser<Char>::JsonParser(Isolate* isolate, Handle<String> source) ...@@ -262,10 +262,6 @@ JsonParser<Char>::JsonParser(Isolate* isolate, Handle<String> source)
} }
cursor_ = chars_ + start; cursor_ = chars_ + start;
end_ = cursor_ + length; end_ = cursor_ + length;
allocation_ = (source->length() >= kPretenureTreshold)
? AllocationType::kOld
: AllocationType::kYoung;
} }
template <typename Char> template <typename Char>
...@@ -453,8 +449,7 @@ bool JsonParser<Char>::ParseElement(Handle<JSObject> json_object) { ...@@ -453,8 +449,7 @@ bool JsonParser<Char>::ParseElement(Handle<JSObject> json_object) {
template <typename Char> template <typename Char>
Handle<Object> JsonParser<Char>::ParseJsonObject() { Handle<Object> JsonParser<Char>::ParseJsonObject() {
HandleScope scope(isolate()); HandleScope scope(isolate());
Handle<JSObject> json_object = Handle<JSObject> json_object = factory()->NewJSObject(object_constructor());
factory()->NewJSObject(object_constructor(), allocation_);
Handle<Map> map(json_object->map(), isolate()); Handle<Map> map(json_object->map(), isolate());
int descriptor = 0; int descriptor = 0;
VectorSegment<ZoneVector<Handle<Object>>> properties(&properties_); VectorSegment<ZoneVector<Handle<Object>>> properties(&properties_);
...@@ -643,19 +638,18 @@ Handle<Object> JsonParser<Char>::ParseJsonArray() { ...@@ -643,19 +638,18 @@ Handle<Object> JsonParser<Char>::ParseJsonArray() {
switch (kind) { switch (kind) {
case PACKED_ELEMENTS: case PACKED_ELEMENTS:
case PACKED_SMI_ELEMENTS: { case PACKED_SMI_ELEMENTS: {
Handle<FixedArray> elems = Handle<FixedArray> elems = factory()->NewFixedArray(elements_size);
factory()->NewFixedArray(elements_size, allocation_);
for (int i = 0; i < elements_size; i++) elems->set(i, *elements[i]); for (int i = 0; i < elements_size; i++) elems->set(i, *elements[i]);
json_array = factory()->NewJSArrayWithElements(elems, kind, allocation_); json_array = factory()->NewJSArrayWithElements(elems, kind);
break; break;
} }
case PACKED_DOUBLE_ELEMENTS: { case PACKED_DOUBLE_ELEMENTS: {
Handle<FixedDoubleArray> elems = Handle<FixedDoubleArray>::cast( Handle<FixedDoubleArray> elems = Handle<FixedDoubleArray>::cast(
factory()->NewFixedDoubleArray(elements_size, allocation_)); factory()->NewFixedDoubleArray(elements_size));
for (int i = 0; i < elements_size; i++) { for (int i = 0; i < elements_size; i++) {
elems->set(i, elements[i]->Number()); elems->set(i, elements[i]->Number());
} }
json_array = factory()->NewJSArrayWithElements(elems, kind, allocation_); json_array = factory()->NewJSArrayWithElements(elems, kind);
break; break;
} }
default: default:
...@@ -757,7 +751,7 @@ Handle<Object> JsonParser<Char>::ParseJsonNumber(int sign, const Char* start) { ...@@ -757,7 +751,7 @@ Handle<Object> JsonParser<Char>::ParseJsonNumber(int sign, const Char* start) {
DCHECK(!std::isnan(number)); DCHECK(!std::isnan(number));
} }
return factory()->NewNumber(number, allocation_); return factory()->NewNumber(number);
} }
namespace { namespace {
...@@ -810,12 +804,11 @@ Handle<String> JsonParser<Char>::MakeString( ...@@ -810,12 +804,11 @@ Handle<String> JsonParser<Char>::MakeString(
chars.length() > kMaxInternalizedStringValueLength) { chars.length() > kMaxInternalizedStringValueLength) {
if (sizeof(LiteralChar) == 1) { if (sizeof(LiteralChar) == 1) {
return factory() return factory()
->NewStringFromOneByte(Vector<const uint8_t>::cast(chars), ->NewStringFromOneByte(Vector<const uint8_t>::cast(chars))
allocation_)
.ToHandleChecked(); .ToHandleChecked();
} }
return factory() return factory()
->NewStringFromTwoByte(Vector<const uint16_t>::cast(chars), allocation_) ->NewStringFromTwoByte(Vector<const uint16_t>::cast(chars))
.ToHandleChecked(); .ToHandleChecked();
} }
......
...@@ -167,7 +167,6 @@ class JsonParser final { ...@@ -167,7 +167,6 @@ class JsonParser final {
Handle<String> ParseJsonString(bool requires_internalization, Handle<String> ParseJsonString(bool requires_internalization,
Handle<String> expected = Handle<String>()); Handle<String> expected = Handle<String>());
Handle<String> ScanJsonString();
// A JSON number (production JSONNumber) is a subset of the valid JavaScript // A JSON number (production JSONNumber) is a subset of the valid JavaScript
// decimal number literals. // decimal number literals.
...@@ -212,7 +211,6 @@ class JsonParser final { ...@@ -212,7 +211,6 @@ class JsonParser final {
inline Handle<JSFunction> object_constructor() { return object_constructor_; } inline Handle<JSFunction> object_constructor() { return object_constructor_; }
static const int kInitialSpecialStringLength = 32; static const int kInitialSpecialStringLength = 32;
static const int kPretenureTreshold = 100 * 1024;
static void UpdatePointersCallback(v8::Isolate* v8_isolate, v8::GCType type, static void UpdatePointersCallback(v8::Isolate* v8_isolate, v8::GCType type,
v8::GCCallbackFlags flags, void* parser) { v8::GCCallbackFlags flags, void* parser) {
...@@ -252,7 +250,9 @@ class JsonParser final { ...@@ -252,7 +250,9 @@ class JsonParser final {
Isolate* isolate_; Isolate* isolate_;
Zone zone_; Zone zone_;
const uint64_t hash_seed_; const uint64_t hash_seed_;
AllocationType allocation_; JsonToken next_;
// Indicates whether the bytes underneath source_ can relocate during GC.
bool chars_may_relocate_;
Handle<JSFunction> object_constructor_; Handle<JSFunction> object_constructor_;
const Handle<String> original_source_; const Handle<String> original_source_;
Handle<String> source_; Handle<String> source_;
...@@ -262,14 +262,11 @@ class JsonParser final { ...@@ -262,14 +262,11 @@ class JsonParser final {
// end_ should never be locally cached across a possible allocation. The scope // end_ should never be locally cached across a possible allocation. The scope
// in which we cache chars has to be guarded by a DisallowHeapAllocation // in which we cache chars has to be guarded by a DisallowHeapAllocation
// scope. // scope.
const Char* chars_;
const Char* cursor_; const Char* cursor_;
const Char* end_; const Char* end_;
const Char* chars_;
JsonToken next_;
LiteralBuffer literal_buffer_; LiteralBuffer literal_buffer_;
// Indicates whether the bytes underneath source_ can relocate during GC.
bool chars_may_relocate_;
// Property handles are stored here inside ParseJsonObject. // Property handles are stored here inside ParseJsonObject.
ZoneVector<Handle<Object>> properties_; ZoneVector<Handle<Object>> properties_;
......
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