-
Notifications
You must be signed in to change notification settings - Fork 30k
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
N-API SharedArrayBuffer api #23279
N-API SharedArrayBuffer api #23279
Conversation
Build failed |
Hi! Did you accidentally close you PR (presumably clicking on "Close and comment" instead of "Comment" button) or this was intentional? |
I saw that the build was cancelled by CI. I thought there may be a compile error or something(I didnt test it my own before making a PR). So I closed the PR intentionally. |
@orange4glace It’s totally fine if a PR doesn’t pass CI at first – you can always create new changes and push to your branch to change them. In this case, could you make sure that when you run |
Oh, I see. I am almost new to git so my apology. I am trying to build it with my Windows 10 but it keeps fail, even with vanila version of it. :| Maybe I'll have to try on linux so I can find out whether it works. Thanks! |
@orange4glace No problem – let us know if we can help in some way! |
@orange4glace |
src/node_api.cc
Outdated
return GET_RETURN_STATUS(env); | ||
} | ||
|
||
napi_status napi_create_external_sharedarraybuffer(napi_env env, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove this one as it isn't something that we can expect other engines to be able to implement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@devsnek Just for context, we also have napi_create_external_arraybuffer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@addaleax then let's not make the same mistake twice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the other engines do not support external arraybuffer and n-api has already some mis-design related to external-arraybuffer api things?
@digitalinfinity can you comment on Chakra support for napi_create_external_arraybuffer (which I think it should since we included in the API) and external shared array buffers? It is an important question as to whether most engines support external shared array buffers ... . |
If this does move forward the new APIs need to start as experimental and be in the section guarded by #ifdef NAPI_EXPERIMENTAL |
@orange4glace for reference in case you have not seen it yet. This covers some of the principles we want to follow for new APIs. https://github.com/nodejs/node/blob/master/doc/guides/adding-new-napi-api.md I'll also add thank you for help with N-API. And one final question, is there a use case where you need to use the external shared buffers that can't be covered with the existing API surface in another way? |
@mhdawson Thanks for the link! I will try to follow those rules for future PRs :] I am currently working on kind of video editor based on Electron. The N-API native module will be loaded on Browser process. So there is mainly three threads involved.
So the second and third thread should share the buffer memory to prevent copying huge size of memory thus improves a performance. At first I came up with ArrayBuffer transfer via postMessage, but some reason the browser crashes when external ArrayBuffer transfer occurs. So rather than finding why, I focused on this SharedArrayBuffer feature. |
I can only guess, but I think there might be a chance you’re running into the same problem that we have with externalized
I’d disagree. This API fills in a gap from the ES spec and adds parity to the If there is a discussion to be had on the externalization feature, we can do that, but if it is a problem (which would surprise me), it also affects existing API. |
@addaleax if this does not go in as |
@addaleax I think we'd agreed (at least on the N-API team) that everything would go in as experimental. We would then group things together and release in a new NAPI_VERSION as opposed to having every new function bump the VERSION. I think this will also minimize the chance that we accidentally release a new N-API function without bumping the NAPI_VERSION number. |
@mhdawson Tbh, that’s seems like very strong rigidity in the release process, but if that’s a rule the team has created, then feel free to ignore me |
Does this need changes? Reviews? A CI run? Would love to see it not get stalled... /ping @nodejs/n-api |
It needs an update so that the new functions are being added as Experimental. (ie guarded by the experimental flag). I'd also like confirmation from @digitalinfinity that it is something that can be implemented by multiple different JavaScript engines. |
I think we can support this one in Node-ChakraCore- @boingoing was going to take a look at adding a JSRT API for this (although by default SharedArrayBuffers are turned of in Chakra, we're looking at having it turned on in a scoped manner) |
@orange4glace Can you do that and rebase to eliminate conflicts? |
@Trott Holy moly! I don't know if I did right?! -0- There were some major changes after my first PR. So I first synced my repo with upstream and added my codes again (c308106) As @gabrielschulhof mentioned, typedarray also needs to be changed but that one is non-experimental and this one(sharedarraybuffer) is experimental so mixing them is maybe a kind of weird thing even though headers and (v8) implementations are separated. |
@orange4glace the implementation of N-API is always experimental. Only the APIs advertised in the header are separated into N-API versions 1-3, and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is heading in the right direction👍 It still needs the followings:
- documentation
- tests
TypedArray
support – which you can safely implement even though the API forSharedArrayBuffer
is experimental, and the API forTypedArray
is not.
I think we have to be careful here. I'm not sure what the right answer is but I think we need to avoid somebody using what they believe is N-API version 3 (which has TypedArray) and then later building against an earlier Node.js version and finding it does not work. I'll have to look at it in more detail to better understand if its an issue or not. |
@mhdawson you're right. Although the implementation never has Thus, I don't think we can have I think we need a |
... and it could use the existing |
There's still an issue we need to investigate. Faced with a |
@mhdawson some observations from running https://gist.github.com/gabrielschulhof/108166bc6e71a755caac6897be5b1f66 against Node.js 8.7.0 and 10.10:
V8 has 2 constructors each for all typed array types such that one accepts an It looks like The cleanest solution though IMO is to introduce a second set of N-APIs that deal with |
Given that |
@nodejs/n-api @orange4glace Does someone want to pick this up and get it across the finish line? |
ping @orange4glace again |
I can now work on this although a quite long time has been passed(Sorry for that! :P). Since the entire napi file structures are changed from the first PR was requested, it seems closing this and reopening a fresh PR might be good. Any ideas? |
@orange4glace no need to close this PR. It's fine if you just reset the branch and start pushing to it again. |
@orange4glace of course, closing it and starting a new one is fine too 🙂 |
In
We can create But, other functions like, for example What's your thoughts? @gabrielschulhof |
8ae28ff
to
2935f72
Compare
This hasn't been updated in a while, is out of date. Closing but can reopen if it is picked back up again and updated. |
Implementing :
napi_create_external_sharedarraybuffer
napi_get_sharedarraybuffer_info
napi_is_sharedarraybuffer
Since V8 api supports external sharedarraybuffer creation, it would be nice if n-api implements this.