Code Monkey home page Code Monkey logo

Comments (6)

danivek avatar danivek commented on August 17, 2024

Hi @Mattii,

I had already thought about adding non blocking code because of performance issues on large payloads, but I have absolutely no idea on how to do that. I know that we can use nextTick or stream, but i never did that.

According to you, wich is the best between process.nextTick and stream ? maybe both ?
How it work if you use these features on browser ?

I agree to not break compatibility and add method like Serializer.serializeAsync().

I will investigate further on best practices for non-blocking code.
If you know how to do that, I am pleased that we can work together on a PR.

Thanks @Mattii

from json-api-serializer.

mattiloh avatar mattiloh commented on August 17, 2024

Great! Sure, let's work together on this feature.

We could use something like https://github.com/sindresorhus/into-stream to convert the data-array into a stream. It pushes an array-item into the stream on each tick (via setImmediate). Now we only need to read this stream and serialize every array-item as it comes, forming the json-api payload step by step. When the stream ends, we just resolve a promise with the completed payload.

If you want, I can start with an implementation next week.

Regarding browser compatibility: this could be difficult. I think browsers don't support setImmediate and I'm not sure about streams there either. Is this a requirement you have for this module? Then we might need to research on that area before.

from json-api-serializer.

danivek avatar danivek commented on August 17, 2024

Personnally I don't use it on client side, and browser compatibility was not my first intention when I make this library. So it's not a requirement actually.

from json-api-serializer.

danivek avatar danivek commented on August 17, 2024

@Mattii

I made a quick try, and it work very well on medium payload (<5000). Execution time take
2x less time at least. But on large payload (10000 object) there is no significant difference on execution time...

from json-api-serializer.

mattiloh avatar mattiloh commented on August 17, 2024

Fine! We could add a note to the README to clarify that it is a node-module and not tested for browsers.

from json-api-serializer.

mattiloh avatar mattiloh commented on August 17, 2024

Sorry, did not read your last comment. I guess doing the serialization async with a stream won't make it faster, but it won't block the loop. If the synchronous serialization takes 10 seconds now, the complete node process is blocked and not able to process any other request, producing 5xx responses...

from json-api-serializer.

Related Issues (20)

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.