lemanschik / web-modules

A Web Module Loader can also be used in WInterCG Standard Supporting Runtimes
The Unlicense
0 stars 1 forks source link

NodeJS API Docs. #7

Open lemanschik opened 1 year ago

lemanschik commented 1 year ago

the trick is we pass functions arrguments and a result shared array buffer directly from the engine into the function.

so it operates on that what we call a handle represented as SharedArray Buffer it is equal to what we do in wasm implicitly

thats what we name a fast ffi call operating on sharedMemory all locking is abstracted by the engine it self no need to code your own logic.

https://github.com/bengl/sbffi shows that effect the essential part is

ffi-napi: 772.013ms <= Nodejs as alsways
sbffi: 29.467ms <= nodejs and shared arraybuffers + call lib
napi-addon: 3.790ms <= napi nativ nodejs addon
napi-addon-sb: 3.352ms <= same as above using sharedBuffer
wasm: 0.847ms <= shared array buffer lib uv of nodejs is now the blocker
js: 0.087ms  <= as less nodejs envolved as possible only lib uv blocked 
web-modules: 0u <= infinity faster.

that means that sbffi which is a slower implementation of this is significant faster and gets faster and faster as more engine layers we drop.

good first learning steps are attempt to use rollup in a repl to construct a new global that only contains what you need a restricted nodejs environment.

also a good learning is to code your own shims patch something in that stuff to fit your needs.