Bun JavaScript Platform Now Supports SI Code Calls

In the platform bun, developed as an alternative to node.js and intended for separate execution of applications written in JavaScript, JSX, and Typescript, an experimental feature has been implemented for compilation and execution of handlers written in SI. Previously, calling low-level code required creating a N-API layer for the V8 engine or compiling the code in the WebAssembly (WASM/WASI) format, which added complexity to development. Now, SI code can be directly built into JavaScript and compiled on-the-fly using the compiler tincccc, as well as dynamically binded libraries.

For working with the language, the Bun: FFI layer is utilized, which compiles the source code into machine instructions, stores it in memory during execution, and automatically converts data types between JavaScript and SI. The overhead expenses when interacting with the compiled SI code are minimized, resulting in a delay of approximately 2 nanoseconds for each call of an external SI function. An example is provided where contacting FFMPEG libraries directly to convert short videos using Bun: FFI significantly reduced the total time of the test task by three times.

Furthermore, in the Bun 1.1.29 release, support for n-API (napi) has been added for SI code. This enhancement allows SI wrappers written in the language to return non-primitive values such as objects, strings, and arrays to JavaScript, in addition to Int and Float types.

The mechanism for calling handlers in the SI language also enables dynamic loading of libraries with C ABI, regardless of the language they were originally written in (e.g., C++, Rust, Zig). This feature allows functions from these libraries to be called without the need for additional processing stages. For instance, JavaScript can now interact with system APIs seamlessly.

/Reports, release notes, official announcements.