Eduard Bondarenko
Eduard Bondarenko

Reputation: 363

Why v8::JSON::Parse from v8 much slower than NodeJS JSON::parse?

I know that NodeJS built on top of V8. That's why it looks so strange, when my c++ wrapper around v8 parses json file (2 Mb) in 394 seconds and NodeJS scripts parses the same json file in 167 seconds.

In C++ I call parse json in this way

v8::MaybeLocal<v8::Value> jsonData = v8::JSON::Parse(isolate, v8::String::NewFromUtf8(isolate, data));

and in NodeJS JSON.parse(data).

Also when I call v8::JSON::Parse in a loop like this

for (int i = 0; i < 1000; i++) {
  v8::JSON::Parse(isolate, v8::String::NewFromUtf8(isolate, data));
}

it eats all my memory and OOM killer kills my app. Why it works in this way ? Maybe this function contains mem leaks or I need to free something.

Many thanks!

Upvotes: 3

Views: 1647

Answers (1)

user3104201
user3104201

Reputation: 356

I only bet that in the pure v8 use, the json returned from 'JSON::parse' is destroyed right away while in node.js, it garbage collected either asynchronously, either in outside the loop. Try to chunk the returned jsons in a resrved vector and see if the performance goes up.

Upvotes: 1

Related Questions