async-json icon indicating copy to clipboard operation
async-json copied to clipboard

reviver and replacer thread

Open vkurchatkin opened this issue 10 years ago • 1 comments

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 reviver in 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 no reviver is 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 toString to 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.

vkurchatkin avatar Aug 02 '15 17:08 vkurchatkin

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

anaisbetts avatar Aug 03 '15 06:08 anaisbetts