-
Notifications
You must be signed in to change notification settings - Fork 462
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
How to generate JsObject in Node.js c++ addon as fast as in pure js? #1074
Comments
And I found the Nan c++ addon is faster than node-addon-api, but still slower than pure JS.... like this:
time cost:
|
Hi @zhuyingda, |
In addition to what Nick has said. After doing some testing (not returning the object, void function) it looks like the addon still takes a while to finish. If your code requires this big for loop to work, then I recommend also trying out the |
I want to figure out how could I generate JSObject in c++ addon also benefit from the optimization which v8 does behind this scenes? |
Hi @NickNaso, thanks for your reply.
it just cost:
And also, in NAN case:
it just cost:
AKA the main time-cost is because of After moving the Object::New() out of the big for loop, it save a lot of time.
This time cost:
Also, I change the NAN c++ addon code to this:
AKA just return a JsNumber to JavaScript but not the big JsObject, the time cost is:
So it seems like it is not slow that pass big JsObject from native side to JavaScript side in NAN c++ addon. Conclusion:
I am still working on this. I want to found the way to generate JsObject in c++ addon as fast as generate JsObject in pure JavaScript. |
This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made. |
This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made. |
I'm also interested in this topic, is there any new clue? |
@Wyctus FYI https://stackoverflow.com/questions/69231342/how-to-generate-jsobject-in-node-js-c-addon-as-fast-as-in-pure-js/69235332?noredirect=1#comment122622138_69235332 |
@zhuyingda Wow, this looks really interesting, thank you for mentioning! :) |
This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made. |
I am new as a Node.js cpp-addon developer, I need to return a very big Object from cpp(Node.js cpp-addon) to Javascript logic, but I found that it is very slow to generate JsObject in C++ addon rather than pure js.
Here is my code and running result:
cpp-addon case:
Running this code time cost:
pure-js case:
Running this code time cost:
Why is this so slow that generate JsObject in cpp-addon? Perhaps it is relative to V8 Hidden-Class?
How could I generate JsObject in cpp-addon faster?
The text was updated successfully, but these errors were encountered: