-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Faster JSONata evaluation by switching from generators to async/await #583
Faster JSONata evaluation by switching from generators to async/await #583
Conversation
Because of inclusion of
|
f64888d
to
c49bf09
Compare
c49bf09
to
9be85b9
Compare
One issue my team has noticed in production is dealing with cancellation of processing. There's no clear way right now to cancel all promises spawned by a JSONata expression if another part of the expression encountered an error. I'm curious to know if your PR handle this somehow or you were able to mitigate this issue some other way? |
This is a great piece of work, thank you for the contribution. |
@andrew-coleman, when can we expect to be released to npm? |
Is there any documentation on what the JavaScript API changes are? The 2.0 release notes highlight this PR as a breaking change, but I can't find any docs on what changes are needed in order to migrate from 1.x to 2.x |
The |
Ah ok. Yeah, that's a pretty major change. So there's no synchronous option at all? We have a bunch of synchronous APIs that make use of JSONata... making them all async will be a major breaking change for us. |
I wonder if adding |
@andrew-coleman Any thoughts on switching between async and sync? This might be best taken to a new issue rather than on a closed PR... |
So, having multiple documents to be processed by some jsonata expression, how do I do that efficiently? |
This PR is greatly inspired by and builds upon @avaidyam's work in #508
Apart from allowing non-blocking/asynchronous functions -
fetch()
,fs.readFile
etc. to run in parallel (as noted by @avaidyam's), there are additional benefits of switching to async/await - performance benefits.I've included two test cases in
performance
directory which contain two example JSONata expressions that take a non-trivial amount of time given an example array with 256 elements (see items.json):Link: https://try.jsonata.org/sPNirb3df (it actually causes
Expression evaluation timeout: Check for infinite loop
in JSONata Exercises)and
Link: https://try.jsonata.org/K4_Qr1Hof
I've used those two cases as a benchmark, all numbers were measured on my Apple M1 Max (I acknowledge this is not an average machine, so your results may vary):
master
branch:async/await
version:case000.json
went down from ~1400ms to ~240ms andcase001.json
from ~1700ms to ~300msI've also measured how long it takes to run the entire test suite (again, on my personal machine so your results may vary), my results below:
master
branch:npm t 20.83s user 1.09s system 138% cpu 15.776 total
async/await
version:npm t 8.14s user 0.62s system 128% cpu 6.846 total
In addition to those changes this PR introduces
nyc
package in favour of istanbul following this comment: gotwarlost/istanbul#904 (comment)