castrum 0.9.9 → 0.9.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +140 -89
- package/Cargo.toml +29 -5
- package/README.md +5 -2
- package/castrum.darwin-arm64.node +0 -0
- package/castrum.darwin-x64.node +0 -0
- package/castrum.linux-arm64-gnu.node +0 -0
- package/castrum.linux-arm64-musl.node +0 -0
- package/castrum.linux-x64-gnu.node +0 -0
- package/castrum.linux-x64-musl.node +0 -0
- package/castrum.linux-x64-v3-gnu.node +0 -0
- package/castrum.win32-x64-msvc.node +0 -0
- package/docs/FFI_BUN_GUIDE.md +8 -4
- package/docs/HOW_TO_ADD_AN_OP.md +12 -9
- package/docs/REPO_MAP.md +10 -6
- package/docs/ai/TREE.md +3 -1
- package/docs/bun-builtins-decision-matrix.md +17 -7
- package/package.json +3 -2
- package/rust/crypto/base64.rs +472 -57
- package/rust/crypto/hashing.rs +68 -0
- package/rust/ffi/crypto.rs +224 -197
- package/rust/ffi/hashing.rs +68 -51
- package/rust/ffi/http.rs +33 -24
- package/rust/ffi/ingress.rs +13 -12
- package/rust/ffi/metrics.rs +8 -7
- package/rust/ffi/payload.rs +26 -23
- package/rust/ffi/probe.rs +18 -11
- package/rust/ffi/route.rs +6 -5
- package/rust/ffi/task.rs +14 -11
- package/rust/ffi/tests.rs +95 -0
- package/rust/ffi/util.rs +13 -0
- package/rust/ffi/validators.rs +36 -29
- package/rust/http/http_date.rs +4 -0
- package/rust/panic_safety.rs +191 -0
- package/rust/payload/sse.rs +78 -5
- package/rust/proptest_suite.rs +131 -1
- package/rust/util/bytes.rs +32 -0
- package/rust/util/text.rs +112 -10
- package/rust/util/validation.rs +34 -0
package/docs/ai/TREE.md
CHANGED
|
@@ -1057,8 +1057,10 @@ docs/
|
|
|
1057
1057
|
│ ├─ bug_report.md
|
|
1058
1058
|
│ └─ feature_request.md
|
|
1059
1059
|
├─ workflows/
|
|
1060
|
+
│ ├─ build-addons.yml # reusable multi-platform addon matrix (ci + release)
|
|
1060
1061
|
│ ├─ ci.yml
|
|
1061
|
-
│
|
|
1062
|
+
│ ├─ codeql.yml
|
|
1063
|
+
│ └─ release.yml # v* tag: verify → build → npm publish → GitHub release
|
|
1062
1064
|
├─ codeql-config.yml
|
|
1063
1065
|
├─ dependabot.yml
|
|
1064
1066
|
└─ PULL_REQUEST_TEMPLATE.md
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
|---|---|---|---|---|
|
|
32
32
|
| `rust.fnv1a64` | `Bun.hash` (wyhash) | 42 B | Bun (parity) | 1.06× |
|
|
33
33
|
| `rust.crc32` | `Bun.hash.crc32` | 42 B | **Bun** | 2.8–8.4× |
|
|
34
|
-
| `rust.xxh3` (new) | `Bun.hash.xxHash3` | 42 B | **Bun** |
|
|
34
|
+
| `rust.xxh3` (new) | `Bun.hash.xxHash3` | 42 B–1 MB | **Bun** (≥1 KB) | 0.97× (≤64 B); ~2.0× (≥1 KB) |
|
|
35
35
|
| `rust.hmacSha256` | `Bun.CryptoHasher("sha256", key)` | 32 B | Bun (mild) | 1.1–1.4× |
|
|
36
36
|
| `rust.passwordHash` (argon2id) | `Bun.password.hashSync` (argon2id) | 12 B | **rust** | 0.55× (rust 1.83×) |
|
|
37
37
|
| `rust.passwordVerify` | `Bun.password.verifySync` | 12 B | **rust** | 0.53× (rust 1.88×) |
|
|
@@ -62,6 +62,14 @@
|
|
|
62
62
|
These rust ops lose to Bun's native implementation on the SAME workload — the
|
|
63
63
|
FFI crossing cannot beat Bun's in-process C++:
|
|
64
64
|
|
|
65
|
+
> Re-swept 2026-09-19 (64 B → 1 MB, interleaved medians + per-call input
|
|
66
|
+
> rotation): the hex and url rows in this table no longer lose — rust hex
|
|
67
|
+
> encode/decode is now 4.7–18.9× / 1.4–6.7× over Buffer, the url codec
|
|
68
|
+
> ~2–3× over `encodeURIComponent`, and base64 decode wins 1.4–6.0×. Only the
|
|
69
|
+
> rows still marked "Prefer Bun" below remain genuinely faster in Bun. See
|
|
70
|
+
> the rows themselves and `src/runtime/builtins.ts` for what the adapter
|
|
71
|
+
> currently delegates.
|
|
72
|
+
|
|
65
73
|
This table mirrors `BUILTIN_OPS` in `src/runtime/builtins.ts` (the 11 ops that
|
|
66
74
|
delegate to Bun built-ins under Bun; `src/selection.ts` derives from it). `fnv1a64` is parity/either but is NOT delegated
|
|
67
75
|
(`Bun.hash` is wyhash — a different algorithm — and rust `fnv1a64` stays the
|
|
@@ -70,13 +78,13 @@ benchmarked impl).
|
|
|
70
78
|
| Op | Recommendation |
|
|
71
79
|
|---|---|
|
|
72
80
|
| `crc32` | Prefer `Bun.hash.crc32`; keep rust as fallback (pure-TS path already exists). |
|
|
73
|
-
| `xxh3` | Prefer `Bun.hash.xxHash3` (~
|
|
81
|
+
| `xxh3` | Prefer `Bun.hash.xxHash3` (~2× at ≥1 KB via AVX2; parity ≤64 B). The rust core is FLAT ~30 GB/s at every size (re-swept 2026-09-19 — the gap is Bun's AVX2 width, not a size pathology); keep it as the Node/non-Bun fast path. The adapter delegates the public `rust.xxh3` to Bun under Bun. |
|
|
74
82
|
| `gzipCompress` | Prefer `Bun.gzipSync` (~2×). **`gzipDecompress` is deliberately NOT delegated** — `Bun.gunzipSync` has no decompression-bomb cap; the rust surface keeps its native 64 MiB-capped path under Bun. |
|
|
75
83
|
| `randomToken` | Prefer `Bun.randomUUIDv7()` (or `crypto.getRandomValues`) for token-sized output; keep rust for byte-precise control. |
|
|
76
84
|
| `hmacSha256` | Prefer `Bun.CryptoHasher("sha256", key)` (1.17× — mild; keep rust batch path, which wins on larger inputs). |
|
|
77
|
-
| `urlEncode` / `urlDecode` |
|
|
78
|
-
| `base64Encode` / `base64UrlEncode` |
|
|
79
|
-
| `hexEncode` | Prefer
|
|
85
|
+
| `urlEncode` / `urlDecode` | Fan-out. Re-swept 2026-09-19 on escape-heavy input the rust LUT+run-copy codec is ~2.8–3.2× (encode) / ~2× (decode) FASTER than `encodeURIComponent` / `decodeURIComponent` — the earlier ~11.5× reading was input/profile-dependent. The current adapter still delegates via `BUILTIN_OPS`. |
|
|
86
|
+
| `base64Encode` / `base64UrlEncode` | rust wins ≤1 KB (encode 1.8–2.3×); parity ≥16 KiB (0.88–1.07× — both AVX2 and memory-bound). Base64 **decode** is the strong rust play (1.4–6.0×). Fine to prefer rust for both; the adapter currently delegates encode to Buffer per `BUILTIN_OPS`. |
|
|
87
|
+
| `hexEncode` / `hexDecode` | Prefer rust: encode 4.7–18.9×, decode 1.4–6.7× over Buffer (faster-hex SIMD + single-pass AVX2 decode kernel; re-swept 2026-09-19 — previously Buffer won). The adapter still delegates to Buffer per `BUILTIN_OPS`. |
|
|
80
88
|
| `httpDate` | Prefer `Date.toUTCString()`. |
|
|
81
89
|
|
|
82
90
|
**Delegation rule of thumb**: rust stays the default only where it beats its
|
|
@@ -96,7 +104,7 @@ genuinely wins or Bun has no equivalent.
|
|
|
96
104
|
### → Implemented primitives (gaps closed)
|
|
97
105
|
| Primitive | Outcome |
|
|
98
106
|
|---|---|
|
|
99
|
-
| `rust.xxh3` (XXH3-64) | Exposed;
|
|
107
|
+
| `rust.xxh3` (XXH3-64) | Exposed; re-swept 2026-09-19: parity ≤64 B, Bun ~2× at ≥1 KB (its AVX2 width; rust is flat 30 GB/s) → the adapter still delegates under Bun (Node keeps the addon path). |
|
|
100
108
|
| `rust.passwordHashBcrypt` / `rust.passwordVerifyBcrypt` | bcrypt `$2b$` PHC; hash parity, verify rust 1.49×. |
|
|
101
109
|
| `rust.pbkdf2Sha256` | PBKDF2-HMAC-SHA256; parity with `node:crypto`, the only sync option in Bun. |
|
|
102
110
|
| UUIDv7 (`uuidv7()`) | `Bun.randomUUIDv7` already wins — delegated to Bun (`crypto.randomUUID` on Node), not built in Rust. |
|
|
@@ -108,7 +116,9 @@ random tokens, and gzip, Bun 1.4's built-ins are already faster than any
|
|
|
108
116
|
FFI-crossing Rust op — the selection layer should prefer them. Rust retains a clear,
|
|
109
117
|
defensible moat exactly where it matters: **argon2id password hashing
|
|
110
118
|
(≈1.9× vs Bun)**, the **zero-DOM / zero-copy parsers and JSON paths** (no Bun
|
|
111
|
-
sync equivalent),
|
|
119
|
+
sync equivalent), **brotli** (no Bun sync API), and — since the 2026-09-19
|
|
120
|
+
re-sweep — the **hex and URL byte codecs and base64 decode** (1.4–18.9× over
|
|
121
|
+
the corresponding Buffer / URI built-ins at every size).
|
|
112
122
|
|
|
113
123
|
## Re-run
|
|
114
124
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "castrum",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.11",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Enterprise-grade Bun + Rust runtime: Rust-accelerated FFI primitives, a production-grade HTTP ingress pipeline, validation, hashing, and JSON processing with benchmark-grade performance.",
|
|
6
6
|
"type": "module",
|
|
@@ -158,7 +158,8 @@
|
|
|
158
158
|
"@napi-rs/cli": {
|
|
159
159
|
"typescript": "6.0.3"
|
|
160
160
|
},
|
|
161
|
-
"hyperid": "^4.0.0"
|
|
161
|
+
"hyperid": "^4.0.0",
|
|
162
|
+
"fast-uri": "^3.1.8"
|
|
162
163
|
},
|
|
163
164
|
"engines": {
|
|
164
165
|
"bun": ">=1.1.0",
|