Comments (6)
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.
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.
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.
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.
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.
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)
- ObjectID (mongodb) should be serialized with .toString() and not treated as an object HOT 2
- Support extracting error class names into the 'title' field of JSON API errors HOT 1
- Error when try to deserialise an included relationship with `alternativeKey` HOT 3
- ErrorMaximum call stack size exceeded if `included` has cross references
- Would you be interested in a conversion to Typescript? HOT 2
- Error instance serialization missing properties HOT 1
- ValidationError: beforeSerialize is not allowed HOT 2
- Incorrectly deserializing relationship when alternativeKey is set from default and relationship data is not in the included array HOT 2
- Case conversion breaks on non-alphanumeric strings
- Unintended object in attributes HOT 2
- Is there an option to remove undefined properties? HOT 1
- The result after serialize will not have `included` if the input doesn't have attributes HOT 5
- Error thrown when relationship is not registered HOT 5
- Having no attributes in the relation data does not add relation to included array
- Use a cache for converting to snake/camel/kebab case HOT 1
- bug: When installed in Angular project, it throws error since it is searching for `fs` HOT 3
- Relationships do not work with ES2015 classes
- bug: Duplicated models from includes are removed from response HOT 1
- Support serialization of only meta HOT 2
- Support for relationship data serialization? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-api-serializer.