This is a terrible idea. 2x best-case performance is nothing. Especially not worth the extra hassle and complexity that it adds to the code. The sad thing about these kinds of articles is that there are people out there who will read this and actually start implementing it in their code.
The cost of parsing JSON
21–30 of 308 posts
Re: The cost of parsing JSON
#22So I guess we should "transpile" static objects into strings that we call with JSON.parse? Not sure if I should end this comment with a /s or not.
Re: The cost of parsing JSON
#23Re: The cost of parsing JSON
#24Title 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
#25 Because the JSON grammar is much simpler than
JavaScript’s grammar, JSON can be parsed more
efficiently than JavaScript.
Hmm.. shouldn't that hold for most programming languages then?Let's try it for PHP:
time php -r 'for ($i=0;$i
So for 10 million repetitions, a small PHP structure is about 20x faster then parsing JSON. But to test the point of the article, one should use the sama data structure it uses (https://raw.githubusercontent.com/WebKit/webkit/ffdd2799d323...) and parse it only once.Re: The cost of parsing JSON
#26This is a terrible idea. 2x best-case performance is nothing. Especially not worth the extra hassle and complexity that it adds to the code. The sad thing about these kinds of articles is that there are people out there who will read this and actually start implementing it in their code.
Re: The cost of parsing JSON
#27Title 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.
Edit: I think you would also need to identify and only optimize objects that are handled immutably. However, my understanding is that you can do that in a compiler/transpiler fairly easily.
Re: The cost of parsing JSON
#28Re: The cost of parsing JSON
#29This is a terrible idea. 2x best-case performance is nothing. Especially not worth the extra hassle and complexity that it adds to the code. The sad thing about these kinds of articles is that there are people out there who will read this and actually start implementing it in their code.
It's not just an idea, it's engineering with analysis. Smack on a pre-processor to wrap your cold start configurations (if they are large) and you'll get a performance boost, is the takeaway.
> 2x best-case performance is nothing
I'm not sure how you can say that with a straight face. Altering the bootup time of many systems by a factor is non-trivial.
Re: The cost of parsing JSON
#30Because the JSON grammar is much simpler than JavaScript’s grammar, JSON can be parsed more efficiently than JavaScript. Hmm.. shouldn't that hold for most programming languages then? Let's try it for PHP: time php -r 'for ($i=0;$i So for 10 million repetitions, a small PHP structure is about 20x faster then parsing JSON. But to test the point of the article, one should use the sama data structure it uses ( https://r…