Skip to main content

Reaktor FFI: The Universal Language Bridge

Reaktor FFI (reaktor-ffi) is the layer that allows any language runtime to interface with Reaktor's graph. The core is written in C++ (not C) to leverage templates, RAII memory management, and SIMD-accelerated operations.

Architecture

The FFI layer has three components:

  1. C++ Core (libreaktor): A C++ library that exposes Reaktor's graph operations and FlexBuffer manipulation. It is a first-class graph runtime alongside Kotlin and TypeScript.
  2. C++ ABI Surface: A thin extern "C" layer on top of the core that provides a stable ABI for language bindings to link against. It accepts and returns FlexBuffer byte arrays as the universal interchange format.
  3. Language Bindings: Each language wraps the C++ ABI surface in idiomatic APIs, handling memory management (RAII), threading, and type mapping.

Three First-Class Graph Runtimes

The graph abstraction (nodes, ports, edges, lifecycle) is implemented in three languages:

RuntimeLanguageUse CaseInterop Mechanism
PrimaryKotlin (commonMain)Business logic, services, and data layer. Compiles to JVM, Native, and JS.In-process on all Kotlin targets. No FFI needed.
PerformanceC++SIMD algorithms (via Highway), numerically sensitive computation, and real-time audio/video.FlexBuffer FFI via C++ ABI surface.
DynamicTypeScriptWeb UI logic, Cloudflare Workers, and Hermes-based CodePush mobile logic.FlexBuffer FFI via Hermes C++ API (mobile) or in-process (V8/Workers).

Performance Portability with Google Highway

The C++ graph runtime uses Google Highway for SIMD-accelerated compute:

  • Performance Portability: The same source code targets x86 (SSE4, AVX2, AVX-512), ARM (NEON, SVE), POWER, WASM, and RISC-V.
  • 5-10x Speedups: For vectorizable workloads like matrix operations, convolutions, and encoding/decoding.
  • Header-only: C++17 with no heavy dependencies. It integrates directly into the libreaktor build.

Language Bindings Roadmap

LanguageBridge MechanismStatusPrimary Use Case
Kotlin/JVMIn-processStableAndroid apps, Spring Boot servers.
Kotlin/NativeIn-processStableiOS apps, native desktop.
Kotlin/JSIn-processStableWeb apps, Cloudflare Workers.
C++In-processExperimentalSIMD compute, neural networks.
TypeScriptIn-process / HermesExperimentalWeb, Workers, CodePush, React Native.
Dart (Flutter)C++ ABI via dart:ffiPlanned (Q4 2026)Flutter bridge.
SwiftC++ ABI via Swift C interopPlanned (Q1 2027)SwiftUI bridge.
RustC++ ABI via extern "C"FutureSystems programming, WASM.
PythonC++ ABI via pybind11FutureML/AI pipelines, data science.