GithubHelp home page GithubHelp logo

async-json's People

Contributors

ljharb avatar michaelficarra avatar mohsen1 avatar rgbkrk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

async-json's Issues

about polyfill

I feel that polyfills are dangerous: you are wrapping a sync method as async method. With the callback / promise you are simulating a async method, but the implementation is synchronously and will block the main thread.

Two solutions: implement a native JSON.parse async or move the sync JSON.parse work at the end of the event loop. I was working in the last option in this repository: https://github.com/Kikobeats/json-parse-async

Effects of background processing of relatively small pieces of data

What strikes me about this feature is that we're asking developers to have some intuition about when something is too big to happen "fast enough" that they need to push it off to async.

In my experience, developers are notoriously bad about reasoning about JS performance, and this seems like a huge welcome mat with a neon sign on the door that says, "please, come abuse the heck out of me with bad jsperf tests backing you up."

I would strongly suggest that the specification be reworded so as to not require that an implementation actually do the processing on some background thread, but merely that they make the results available via a promise that will have (at least) an event-loop deferral to make the operation "async" (and yet not necessarily parallel, background'ish).

Then an implementation can make some guess based on input size if they should go to the trouble to do it on another background thread (a la Web Workers) or if they should just do a sync JSON.xxxx(..) call and resolve the promise with it right away.

From the calling code's perspective, the behavior will be predictably async, but from the implementation's perspective, the engine has a chance to do different things when it feels it's better to do so.

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 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.