Re:The Cost of JavaScript in 2019
by pbhjpbhj on Sunday June 30, 2019 @02:52PM
(#20319765)
IANAProgrammer but couldn't it do like try..catch and assume it's JSON compatible and fall back to the [much] slower method if the parse fails? Does that cost too much time/resources?
[ Parent
| on HN ]
Isn’t that effectively what a backtracking parser does? My naive guess is that’s already roughly how the JS parser works, and that process is what makes it slower than the simpler JSON parser.
Re:The Cost of JavaScript in 2019
by daleharvey on Sunday June 30, 2019 @03:10PM
(#20319876)
That would make all JavaScript that has non JSON object literals (most JS code) slower
How much slower?
We already established it's far slower parsing js; in most cases JSON parsing would fail - IIRC - on the first character ^[^{] ... so would it be worth being slower by the time it takes to check the first character, and then only JavaScript that started with { would be slower. Which I guess is virtually none.
I suppose those sorts of questions are part of what makes language design interesting.