onnxruntime/js/node
Segev Finer 29b1106033
[node] Switch to setImmediate to avoid starving the Node.js event loop (#19610)
### Description
<!-- Describe your changes. -->
Switch to setImmediate to avoid starving the Node.js event loop

There should really be a true async version though, running
computationally intensive things on the event loop will stop everything
else from happening while it is running, e.g. a web server from
answering requests.

This can be done by wrapping `RunAsync` behind a
[`napi::Promise`](https://github.com/nodejs/node-addon-api/blob/main/doc/promises.md)
to run on the onnxruntime thread pool or [`AsyncWorker`](
https://github.com/nodejs/node-addon-api/blob/main/doc/async_worker.md)
for the Node.js/libuv thread pool.

### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
Without this, if you run inference in a tight loop, without anything
else in between that is async/deferred, `process.nextTick` will lead to
starving the event loop and not letting anything else run,
`setImmediate` at least lets the event loop spin between calls to `run`.

See
https://dev.to/ynmanware/setimmediate-settimeout-and-process-nexttick-3mfd

Contributed on behalf of [Swimm](https://swimm.io/)
2024-02-22 18:53:50 -08:00
..
lib [node] Switch to setImmediate to avoid starving the Node.js event loop (#19610) 2024-02-22 18:53:50 -08:00
script [js] update prepack script to use exact version (#17484) 2023-09-13 00:07:16 -07:00
src [js/node] support manually dispose session (#18655) 2023-12-19 16:20:00 -08:00
test [js] update a few packages (#18499) 2023-11-17 22:40:51 -08:00
.gitignore
.npmignore
CMakeLists.txt Added DML and CUDA provider support in onnxruntime-node (#16050) 2023-08-25 16:57:06 -07:00
package-lock.json [ORT 1.17.0 release] Bump up version to 1.18.0 (#19170) 2024-01-17 11:18:32 -08:00
package.json [ORT 1.17.0 release] Bump up version to 1.18.0 (#19170) 2024-01-17 11:18:32 -08:00
README.md link to docs incorrect for js/web/node (#18960) 2024-01-03 17:30:24 -08:00
tsconfig.json [js/web] fix typescript type check (#18343) 2023-11-10 16:03:38 -08:00

ONNX Runtime Node.js Binding

ONNX Runtime Node.js binding enables Node.js applications to run ONNX model inference.

Usage

Install the latest stable version:

npm install onnxruntime-node

Refer to ONNX Runtime JavaScript examples for samples and tutorials.

Requirements

ONNXRuntime works on Node.js v12.x+ or Electron v5.x+.

Following platforms are supported with pre-built binaries:

  • Windows x64 CPU NAPI_v3
  • Linux x64 CPU NAPI_v3
  • MacOS x64 CPU NAPI_v3

To use on platforms without pre-built binaries, you can build Node.js binding from source and consume it by npm install <onnxruntime_repo_root>/js/node/. See also instructions for building ONNX Runtime Node.js binding locally.

GPU Support

Right now, the Windows version supports only the DML provider. Linux x64 can use CUDA and TensorRT.

License

License information can be found here.