Live data from Hacker News

The cost of parsing JSON

v8.dev

1–10 of 308 posts

Re: The cost of parsing JSON

#2
Title correction: it's faster to parse and initialize using JSON than to parse and compile the code required to initialize Objects directly. If the code is already compiled, it's much faster to initialize in code. At least that's my understanding of the linked article.

Re: The cost of parsing JSON

#6
post #3

Does this apply to other JS engines or only V8?

Look at the chart specifically:

> JSON.parse('…') is much faster to parse, compile, and execute compared to an equivalent JavaScript literal — not just in V8 (1.7× as fast), but in all major JavaScript engines.

Re: The cost of parsing JSON

#8
post #5
post #3

Does this apply to other JS engines or only V8?

I was wondering that too. No mention of Firefox or Safari. There is more than one browser/render engine out there. Don't design for the monoculture.

JavascriptCore, Chakra and Spidermonkey appear in the benchmark...

Re: The cost of parsing JSON

#9

Title correction: it's faster to parse and initialize using JSON than to parse and compile the code required to initialize Objects directly. If the code is already compiled, it's much faster to initialize in code. At least that's my understanding of the linked article.

I think your understanding is correct. The relevant quote:

> As long as the JSON string is only evaluated once, the JSON.parse approach is much faster compared to the JavaScript object literal, especially for cold loads.

Re: The cost of parsing JSON

#10
post #8
post #5

Earlier quoted context omitted.

I was wondering that too. No mention of Firefox or Safari. There is more than one browser/render engine out there. Don't design for the monoculture.

JavascriptCore, Chakra and Spidermonkey appear in the benchmark...

ah I totally missed that! It's a link to their other benchmarks under the main graph; easy to miss:

https://github.com/GoogleChromeLabs/json-parse-benchmark

Post reply on HN