async-json
async-json copied to clipboard
reviver and replacer thread
Let's say some day it will be possible to parse JSON in a background thread. That's what this whole thing is about. There still would be a problem with reviver and replacer functions. There are two options:
- they run on the main thread. In case of parsing we either produce intermediate structure in a background thread and then build actual object in the main thread or we can parse in a background thread without taking
reviverin account and do some post-processing in the main thread after. Either way this damages performance (except in the latter case we can skip post-process if noreviveris passed). Things are reversed with stringify: pre-processing instead of post-processing. - they run on a background thread. This means two things: we need to spawn full VM for each thread dedicated to JSON tasks and we need to serialize functions via
toStringto pass them to a different VM which breaks closure semantics.
Both options seems pretty bad, so it's probably easier to leave out reviver and replacer arguments altogether.
Reviver / replacer seems ill-specified in its current form as well - does it walk the tree recursively? Are 'key' and 'value' strings or already-parsed sections? :+1: to dropping this from the spec, the async part is a clear win and easy for everyone to agree on