-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add JS-side cache of wasm table entries. NFC #15286
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
Conversation
a783acb
to
4c94ac8
Compare
These new functions are are all designed to be internal-only library functions.. but we don't currently have a good way to mark them as such. Perhaps I should at least document them as such? |
Once we figure solve #15242 we can mark these are internal-only members. |
This approach sgtm. Overall it is like #14534 but with a new API instead of a "polyfill". I imagine this is more compact in code size, but that might be worth verifying. |
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.
Code also looks good.
I'll wait for @juj since this is basically his code split into a separate PR. |
Thanks, lgtm |
I think I will wait for #15294 to land so I can mark these new functions as |
Split out from #13844, this is an internal optimization that avoids repeated calls to table.get.
4c94ac8
to
0f9febb
Compare
wasmTableMirror[idx] = func; | ||
}, | ||
|
||
$getWasmTableEntry__internal: true, |
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.
I don't think setWasmTableEntry and getWasmTableEntry should be marked internal? This promotes the scenario where our internal library_x.js files use APIs that are not enabled for end users to utilize, which is not good design. (e.g. the embind.js and library.js changes above)
End user JS libraries should be at the "same power level" as our own core-provided libraries whenever possible, because a lot of users use these libraries to mimic their own libraries off of. That will avoid us from building up issues like we have e.g. with the existence of the deps_info.py script.
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.
Sure, if you think we want to commit to maintaining these APIs in the long term, and they are not just an internal detail then we should make them public.
However, I think we should always try to keep things internal where possible to avoid API surface creep, which make it hard for us to evolve or remove APIs over time.
The whole point of making certain JS library functions internal
is to limit the power to user-level JS library file to see our internal symbols. There are inherently two tiers of exposure here by design.
Currently the use of an internal symbol only generates a warning.. so folks can still use internal symbols today.
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.
In my mind the point of marking something as internal is to prevent external JS library files from depending on something that we might want to change or remove in the future. So this is really a decision we need to make a on per-symbol basis, right?
I'm OK with making these particular symbols as externally visible, but I'm wonder what you think would make a good criteria for an internal symbol? Perhaps, as in this case we could say that if we used a symbol in more than one library file it should be considered externally visible/useful?
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.
Sure, if you think we want to commit to maintaining these APIs in the long term,
I mean, what API should a JS developer then use to invoke a wasm function pointer from JS if not getWasmTableEntry
?
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.
Sure, if you think we want to commit to maintaining these APIs in the long term,
I mean, what API should a JS developer then use to invoke a wasm function pointer from JS if not
getWasmTableEntry
?
This change was not intended to be an API change, just and internal optimization.
The existing makeDynCaller
/ dynCall
APIs are still public and did not change. We also (IIUC) have a new public API coming in the form of your wbind
, right?
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.
I'll look at adding the wbind()
API then.
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.
I kind of like the internal symmetry of getWasmTableEntry/setWasmTableEntry
. Could wbind not just be an external-facing alias of getWasmTableEntry
?
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.
I am not so hot on exposing two functions that do the same. Having internal library code call getWasmTableEntry
and public API to use wbind
that do the same does not make sense.
Also I don't think that the symmetry of getWasmTableEntry
/setWasmTableEntry
is particularly interesting, because getWasmTableEntry
is a public API function, whereas setWasmTableEntry
is an internal implementation API? (afaik there is never a reason for external users to call it, is there?)
Another option is that we drop the plan for the wbind
alias, and expose getWasmTableEntry
as the public facing API?
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.
I guess thats not a bad option... I find getWasmTableEntry
to be more explict about what its doing than wbind which makes me things of embind and other bindings systems. (But then again we had this debate over on #13844 and I think I gave on finding a better name.. but if you are OK with getWasmTableEntry
I think we could go for it).. @kripken WDYT about this being the public name for this?
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.
I agree getWasmTableEntry
sounds like a reasonable API name. It is clear and unambiguous.
I added this line myself back in emscripten-core#15286 but I guess I forgot that JS arrays will magically grow on their own.
I added this line myself back in emscripten-core#15286 but I guess I forgot that JS arrays will magically grow on their own.
I added this line myself back in emscripten-core#15286 but I guess I forgot that JS arrays will magically grow on their own.
I added this line myself back in emscripten-core#15286 but I guess I forgot that JS arrays will magically grow on their own.
I added this line myself back in #15286 but I guess I forgot that JS arrays will magically grow on their own.
Split out from #13844, this is an internal optimization
that avoids repeated calls to table.get.