Commit dda75616 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[json] Use SmallVector to buffer properties and elements

This improves performance a little for especially small parsed
objects, e.g., parsing json-parse-financial data in kraken 100.000
times goes from 3.25 s to 3.1 or below.

Change-Id: Ic9b668b44fc766da9d8ad03f51924f7dd8b5cc7a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2752881Reviewed-by: 's avatarVictor Gomes <victorgomes@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73360}
parent d193e90c
......@@ -401,7 +401,7 @@ Handle<Map> ParentOfDescriptorOwner(Isolate* isolate, Handle<Map> maybe_root,
template <typename Char>
Handle<Object> JsonParser<Char>::BuildJsonObject(
const JsonContinuation& cont,
const std::vector<JsonProperty>& property_stack, Handle<Map> feedback) {
const SmallVector<JsonProperty>& property_stack, Handle<Map> feedback) {
size_t start = cont.index;
int length = static_cast<int>(property_stack.size() - start);
int named_length = length - cont.elements;
......@@ -645,7 +645,7 @@ Handle<Object> JsonParser<Char>::BuildJsonObject(
template <typename Char>
Handle<Object> JsonParser<Char>::BuildJsonArray(
const JsonContinuation& cont,
const std::vector<Handle<Object>>& element_stack) {
const SmallVector<Handle<Object>>& element_stack) {
size_t start = cont.index;
int length = static_cast<int>(element_stack.size() - start);
......@@ -686,12 +686,10 @@ Handle<Object> JsonParser<Char>::BuildJsonArray(
template <typename Char>
MaybeHandle<Object> JsonParser<Char>::ParseJsonValue() {
std::vector<JsonContinuation> cont_stack;
std::vector<JsonProperty> property_stack;
std::vector<Handle<Object>> element_stack;
SmallVector<JsonProperty> property_stack;
SmallVector<Handle<Object>> element_stack;
cont_stack.reserve(16);
property_stack.reserve(16);
element_stack.reserve(16);
JsonContinuation cont(isolate_, JsonContinuation::kReturn, 0);
......@@ -833,7 +831,7 @@ MaybeHandle<Object> JsonParser<Char>::ParseJsonValue() {
}
}
value = BuildJsonObject(cont, property_stack, feedback);
property_stack.resize(cont.index);
property_stack.resize_no_init(cont.index);
Expect(JsonToken::RBRACE);
// Return the object.
......@@ -852,7 +850,7 @@ MaybeHandle<Object> JsonParser<Char>::ParseJsonValue() {
if (V8_LIKELY(Check(JsonToken::COMMA))) break;
value = BuildJsonArray(cont, element_stack);
element_stack.resize(cont.index);
element_stack.resize_no_init(cont.index);
Expect(JsonToken::RBRACK);
// Return the array.
......
......@@ -5,6 +5,7 @@
#ifndef V8_JSON_JSON_PARSER_H_
#define V8_JSON_JSON_PARSER_H_
#include "src/base/small-vector.h"
#include "src/execution/isolate.h"
#include "src/heap/factory.h"
#include "src/objects/objects.h"
......@@ -155,6 +156,8 @@ class JsonParser final {
static constexpr uc32 kInvalidUnicodeCharacter = static_cast<uc32>(-1);
private:
template <typename T>
using SmallVector = base::SmallVector<T, 16>;
struct JsonContinuation {
enum Type : uint8_t { kReturn, kObjectProperty, kArrayElement };
JsonContinuation(Isolate* isolate, Type type, size_t index)
......@@ -287,10 +290,10 @@ class JsonParser final {
Handle<Object> BuildJsonObject(
const JsonContinuation& cont,
const std::vector<JsonProperty>& property_stack, Handle<Map> feedback);
const SmallVector<JsonProperty>& property_stack, Handle<Map> feedback);
Handle<Object> BuildJsonArray(
const JsonContinuation& cont,
const std::vector<Handle<Object>>& element_stack);
const SmallVector<Handle<Object>>& element_stack);
// Mark that a parsing error has happened at the current character.
void ReportUnexpectedCharacter(uc32 c);
......
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