Optimize parseLiteral for number-heavy JSON files (ala GeoJSON)#34
Optimize parseLiteral for number-heavy JSON files (ala GeoJSON)#34aeschli merged 2 commits intomicrosoft:masterfrom
Conversation
|
Cool. Do you have examples of numbers that need to go through JSON.parse ? We should add some test cases: https://github.com/microsoft/node-jsonc-parser/blob/master/src/test/json.test.ts#L180 |
|
Good call. I switched from According to MDN the only cases Number(...) may not have JSON-parity are when there is a leading zero, for example |
|
Actually, the scanner in scanNumber already ensures that the number format is correct following the spec from https://www.json.org/json-en.html. You changes look good. Any additional tests you want to add or are we already covered well enough? |
|
I think the tests are already sufficient, I double checked to make sure exponent corner cases were tested. Thanks! |
|
Hi @aeschli , are there any updates on this PR? Thanks! |
|
@mbullington Sorry for the wait, thanks for the PR! |
When parsing number-heavy files like GeoJSON, trying the naive
parseFloatfirst then going for full JSON compatibility ifNaNprovides meaningful performance benefits.Tried on a 75MB GeoJSON file, raw parse time was ~3500ms before change and ~2600-2700ms after.
Best.