doc: add v8 fast api contribution guidelines#46199
doc: add v8 fast api contribution guidelines#46199nodejs-github-bot merged 7 commits intonodejs:mainfrom
Conversation
|
Review requested:
|
4944ab5 to
dcc756f
Compare
dcc756f to
5a5669f
Compare
5a5669f to
a2251da
Compare
a2251da to
177f200
Compare
| Node.js uses [V8](https://github.com/v8/v8) as the JavaScript engine. | ||
| In order to provide fast paths for functions that are called quite often, | ||
| V8 proposes the usage of `fast api calls` that does not use any of the V8 | ||
| internals, but uses internal C functions. |
There was a problem hiding this comment.
internal C functions is rather ambiguous. Also, V8 internals usually refers to the non-public V8 API, which we try not to use in any case. Lastly, if I remember correctly, V8 API calls are allowed to some degree. Not performing any allocations on the V8 heap is what's critical. (Unless this changed since I last worked on fast API calls.)
There was a problem hiding this comment.
I see. Thanks! Can you give an example of V8 API call, without any allocation on the V8 heap?
There was a problem hiding this comment.
I might be wrong, but I think @MayaLekova implemented a fast API that relies on GetAlignedPointerFromInternalField in 6cfba9f, for example. @devsnek might know more about the exact conditions for which APIs are allowed.
There was a problem hiding this comment.
You are right. You can access pre-existing/pre-allocated data from the fast apis. I thought it was inferred from the documentation (at least I assumed). Is there any specific wording you'd like me to change?
There was a problem hiding this comment.
I've updated the documentation.
There was a problem hiding this comment.
[...] Not performing any allocations on the V8 heap is what's critical.
Indeed that's still the case, and until we have the current GC architecture, it will stay like this. Possible future relaxation of this rule might come with conservative stack scanning. Please note that this also leads to the limitation for not calling back into JS code (I think this was discussed in this thread too).
Some brief background on the support for various types in V8 could be found in this external doc.
177f200 to
da9f97e
Compare
I updated the example. Thanks for the hint! 🥇 💯 |
RafaelGSS
left a comment
There was a problem hiding this comment.
I think you should mention this file in the src/README.md too.
|
Awesome @anonrig 🙌🏼 Learned a lot just by reading the PR ^^ |
90c81b8 to
66a8977
Compare
| * Throwing errors is not available on fast API, but can be done | ||
| through the fallback to slow API. |
There was a problem hiding this comment.
| * Throwing errors is not available on fast API, but can be done | |
| through the fallback to slow API. | |
| * Throwing errors is not available from within a fast API call, but can be done | |
| through the fallback to the slow API. |
There was a problem hiding this comment.
Perhaps it's also better to suggest that since in principal, the fast API and the slow API should behave the same to avoid bugs, it's better not to throw errors in the slow API either and just update some flags and return to the JS land to throw?
There was a problem hiding this comment.
I agree in principal with @joyeecheung, but that is not a limitation of a V8 Fast API declaration, but an implementation recommendation. I think it should not be included in this documentation, but in a more style specific documentation like README.md?
| In V8, the options fallback is defined as `FastApiCallbackOptions` inside | ||
| [`v8-fast-api-calls.h`](../../deps/v8/include/v8-fast-api-calls.h). | ||
|
|
||
| * C++ land |
There was a problem hiding this comment.
It aligns with other sections in the same file for mentioning the context of the example it's referring to. Do you have a recommendation for an alternative?
Commit Queue failed- Loading data for nodejs/node/pull/46199 ✔ Done loading data for nodejs/node/pull/46199 ----------------------------------- PR info ------------------------------------ Title doc: add v8 fast api contribution guidelines (#46199) Author Yagiz Nizipli (@anonrig) Branch anonrig:docs-fast-api -> nodejs:main Labels doc, author ready, commit-queue-squash Commits 7 - doc: add v8 fast api contribution guidelines - fixup! doc: add v8 fast api contribution guidelines - fixup! doc: add v8 fast api contribution guidelines - fixup! doc: add v8 fast api contribution guidelines - fixup! doc: add v8 fast api contribution guidelines - fixup! doc: add v8 fast api contribution guidelines - fixup! doc: add v8 fast api contribution guidelines Committers 1 - Yagiz Nizipli PR-URL: https://github.com/nodejs/node/pull/46199 Reviewed-By: Matteo Collina Reviewed-By: Robert Nagy Reviewed-By: Darshan Sen Reviewed-By: Rafael Gonzaga Reviewed-By: James M Snell ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/46199 Reviewed-By: Matteo Collina Reviewed-By: Robert Nagy Reviewed-By: Darshan Sen Reviewed-By: Rafael Gonzaga Reviewed-By: James M Snell -------------------------------------------------------------------------------- ℹ This PR was created on Fri, 13 Jan 2023 14:07:12 GMT ✔ Approvals: 5 ✔ - Matteo Collina (@mcollina) (TSC): https://github.com/nodejs/node/pull/46199#pullrequestreview-1266448194 ✔ - Robert Nagy (@ronag) (TSC): https://github.com/nodejs/node/pull/46199#pullrequestreview-1248744183 ✔ - Darshan Sen (@RaisinTen) (TSC): https://github.com/nodejs/node/pull/46199#pullrequestreview-1249572133 ✔ - Rafael Gonzaga (@RafaelGSS) (TSC): https://github.com/nodejs/node/pull/46199#pullrequestreview-1253500941 ✔ - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/46199#pullrequestreview-1262907890 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2023-01-20T03:25:41Z: https://ci.nodejs.org/job/node-test-pull-request/49099/ ⚠ Commits were pushed after the last Full PR CI run: ⚠ - fixup! doc: add v8 fast api contribution guidelines - Querying data for job/node-test-pull-request/49099/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncuhttps://github.com/nodejs/node/actions/runs/3992434537 |
|
Landed in 7dd4583 |
PR-URL: #46199 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #46199 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #46199 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
I'm introducing a guideline to define and share the limitations/caveats and experiences I've gained from researching on this topic. This would help new contributors to add fast APIs to existing functions.
Referencing: nodejs/performance#23