3 ms·
This is happening way before the JIT phase, at the parsing phase. And the reason it can't be as fast as a JSON parse is explained in the article: The grammar o
by bzbarsky 7y ago
This is happening way before the JIT phase, at the parsing phase.
And the reason it can't be as fast as a JSON parse is explained in the article: The grammar of JSON is much simpler. The literal parser in normal JS needs to deal with things like:
const data = { foo: /* something*/ 42, [barRef]: 1337 };
so needs to do more branching than a JSON parser. And yes, you can pre-scan the string to make sure it's not doing anything like that... but that probably already costs more than the tokenizer phase of a JSON parse, and it's overhead you still need to do that a JSON parse doesn't have to do.