Skip to content

Commit a209242

Browse files
authored
feat: add optional drift-core rust acceleration path (#121)
* Commit * Try running mysql2 e2e sequentially * Try fix * Fix * Print logs * Fix mock clientType * Add more diagnostics output * Try this * Try again * Try this * Try again * Add more diagnostics * Try this * Cleanup * Fix
1 parent 05784cf commit a209242

38 files changed

Lines changed: 1142 additions & 702 deletions

File tree

.github/workflows/e2e.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ jobs:
5959
- name: Run E2E tests for ${{ matrix.library }}
6060
env:
6161
DOCKER_DEFAULT_PLATFORM: linux/amd64
62+
TUSK_USE_RUST_CORE: "1"
6263
TUSK_CLI_VERSION: ${{ steps.tusk-version.outputs.version }}
6364
# Required for Firestore e2e tests
6465
FIREBASE_PROJECT_ID: ${{ vars.FIREBASE_PROJECT_ID }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,5 @@ Thumbs.db
5050
**/e2e-tests/**/.tusk/traces/
5151

5252
.direnv
53+
experimental/
54+
benchmarks/results/

docs/rust-core-bindings.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Rust Core Bindings
2+
3+
This document explains how Rust acceleration works in the Node SDK, how to enable it, and what fallback behavior to expect.
4+
5+
## Overview
6+
7+
The SDK can offload selected hot-path logic to Rust via Node bindings (`@use-tusk/drift-core-node`), defined in the [`drift-core`](https://github.com/Use-Tusk/drift-core) repository. This is controlled by an environment flag and is designed to fail open.
8+
9+
At a high level:
10+
11+
- Node SDK logic remains the source of truth.
12+
- Rust paths are opportunistic optimizations.
13+
- If Rust is unavailable or fails at runtime, SDK behavior falls back to JavaScript equivalents.
14+
15+
## Enablement
16+
17+
Set:
18+
19+
```bash
20+
TUSK_USE_RUST_CORE=1
21+
```
22+
23+
Truthy values are `1` and `true` (case-insensitive). Any other value is treated as disabled.
24+
25+
## Installation Requirements
26+
27+
The Node SDK currently includes `@use-tusk/drift-core-node` as a regular dependency.
28+
29+
Notes:
30+
31+
- There is no Node equivalent of Python extras like `[rust]`.
32+
- Rust acceleration is still runtime-gated by `TUSK_USE_RUST_CORE`.
33+
- If the native binding cannot be loaded on a machine, the SDK continues on JavaScript code paths.
34+
35+
## Platform Coverage and Native Binary Concerns
36+
37+
Node native bindings depend on OS/arch/libc compatibility of published prebuilt artifacts.
38+
39+
Practical implications:
40+
41+
- Some platforms may not have a matching native artifact.
42+
- On such platforms, direct use of `@use-tusk/drift-core-node` can fail at runtime.
43+
- Within `drift-node-sdk`, Rust helper loading is guarded and fails open to non-Rust paths.
44+
45+
Unlike Python wheels, this concern appears as Node native addon compatibility rather than wheel tag compatibility.
46+
47+
## Fallback Behavior
48+
49+
The bridge module is fail-open:
50+
51+
- Rust calls are guarded behind a binding loader.
52+
- If `TUSK_USE_RUST_CORE` is unset/falsey, Rust is skipped.
53+
- If loading or a Rust call fails, helper functions return `null`.
54+
- Calling code then uses the existing JavaScript implementation.
55+
56+
This means users do not need Rust installed to run the SDK when Rust acceleration is disabled or unavailable.
57+
58+
## Practical Guidance
59+
60+
- Default production-safe posture: keep Rust disabled unless your deployment matrix is tested.
61+
- Performance posture: enable Rust and benchmark on your workloads before broad rollout.
62+
- Reliability posture: keep parity/smoke tests in CI to detect drift between JS and Rust paths.

0 commit comments

Comments
 (0)