castrum 0.7.0 → 0.9.1

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.
Files changed (207) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +154 -368
  3. package/castrum.linux-x64-gnu.node +0 -0
  4. package/dist/index.d.ts +2763 -0
  5. package/dist/index.js +8707 -0
  6. package/docs/API.md +337 -0
  7. package/docs/ARCHITECTURE.md +507 -0
  8. package/docs/BENCHMARKS.md +343 -0
  9. package/docs/CASE_STUDY.md +240 -0
  10. package/docs/ENVIRONMENT.md +81 -0
  11. package/docs/FFI_BUN_GUIDE.md +327 -0
  12. package/docs/GETTING_STARTED.md +192 -0
  13. package/docs/INGRESS-ROUTER.md +81 -0
  14. package/docs/INGRESS.md +746 -0
  15. package/docs/NATIVE-ROUTE.md +53 -0
  16. package/docs/REPO_MAP.md +279 -0
  17. package/docs/adr/0001-two-wire-formats.md +39 -0
  18. package/docs/adr/0002-zero-dom-fast-schema.md +38 -0
  19. package/docs/adr/0003-bun-builtins-delegation.md +43 -0
  20. package/docs/bun-builtins-decision-matrix.md +115 -0
  21. package/index.ts +44 -8
  22. package/package.json +98 -33
  23. package/src/ingress/body.ts +289 -0
  24. package/src/ingress/constants.ts +220 -48
  25. package/src/ingress/context.ts +136 -0
  26. package/src/ingress/decode/baked-result.ts +121 -0
  27. package/src/ingress/decode/fast-result.ts +160 -0
  28. package/src/ingress/decode/packed-sections.ts +56 -0
  29. package/src/ingress/decode/result-base.ts +172 -0
  30. package/src/ingress/errors.ts +72 -0
  31. package/src/ingress/fast.ts +152 -1021
  32. package/src/ingress/handlers.ts +639 -1001
  33. package/src/ingress/headers/baked-templates.ts +102 -0
  34. package/src/ingress/headers/cors.ts +44 -0
  35. package/src/ingress/headers/fast-templates.ts +238 -0
  36. package/src/ingress/headers/hsts.ts +83 -0
  37. package/src/ingress/health.ts +68 -0
  38. package/src/ingress/index.ts +142 -405
  39. package/src/ingress/metrics.ts +132 -0
  40. package/src/ingress/options.ts +197 -0
  41. package/src/ingress/packing/gather-raw-headers.ts +139 -0
  42. package/src/ingress/packing/header-packing.ts +75 -0
  43. package/src/ingress/packing/input-packer.ts +164 -0
  44. package/src/ingress/packing/scratch.ts +50 -0
  45. package/src/ingress/packing/select-headers.ts +102 -0
  46. package/src/ingress/response/error-bodies.ts +75 -0
  47. package/src/ingress/response/terminal.ts +59 -0
  48. package/src/ingress/router.ts +237 -0
  49. package/src/ingress/routes/common.ts +79 -0
  50. package/src/ingress/routes/delete.ts +14 -0
  51. package/src/ingress/routes/echo.ts +107 -0
  52. package/src/ingress/routes/fallback.ts +23 -0
  53. package/src/ingress/routes/head.ts +27 -0
  54. package/src/ingress/routes/index.ts +11 -0
  55. package/src/ingress/routes/json-write.ts +129 -0
  56. package/src/ingress/routes/options.ts +26 -0
  57. package/src/ingress/routes/read.ts +35 -0
  58. package/src/ingress/routes/responder.ts +159 -0
  59. package/src/ingress/server-node.ts +376 -0
  60. package/src/ingress/server.ts +475 -0
  61. package/src/ingress/shared.ts +132 -0
  62. package/src/ingress/status.ts +97 -0
  63. package/src/ingress/types.ts +191 -0
  64. package/src/integration/batch.ts +58 -0
  65. package/src/integration/index.ts +29 -0
  66. package/src/integration/pipeline.ts +220 -0
  67. package/src/integration/streaming.ts +78 -0
  68. package/src/integration/websocket.ts +93 -0
  69. package/src/loader/batch.ts +137 -0
  70. package/src/loader/cost.ts +105 -0
  71. package/src/loader/index.ts +745 -0
  72. package/src/loader/ops.ts +657 -0
  73. package/src/loader/state.ts +84 -0
  74. package/src/loader/types.ts +145 -0
  75. package/src/native/ffi/constants.ts +58 -0
  76. package/src/native/ffi/selftest.ts +729 -0
  77. package/src/native/ffi/types.ts +474 -0
  78. package/src/native/ffi.ts +1775 -0
  79. package/src/native/index.ts +8 -207
  80. package/src/native/loader.ts +240 -0
  81. package/src/native/types/instances.ts +274 -0
  82. package/src/native/types.ts +401 -0
  83. package/src/runtime/builtins.ts +131 -0
  84. package/src/runtime/codec.ts +147 -0
  85. package/src/runtime/detect.ts +36 -0
  86. package/src/runtime/index.ts +28 -0
  87. package/src/runtime/native.ts +35 -0
  88. package/src/runtime/server.ts +31 -0
  89. package/src/runtime/transport.ts +64 -0
  90. package/src/runtime/types.ts +173 -0
  91. package/src/runtime/uuid.ts +45 -0
  92. package/src/runtime/websocket.ts +30 -0
  93. package/src/rust-ffi/addon.ts +10 -0
  94. package/src/rust-ffi/batch/build.ts +155 -0
  95. package/src/rust-ffi/batch/index.ts +8 -0
  96. package/src/rust-ffi/batch/types.ts +92 -0
  97. package/src/rust-ffi/client.ts +87 -0
  98. package/src/rust-ffi/context.ts +193 -0
  99. package/src/rust-ffi/index.ts +51 -541
  100. package/src/rust-ffi/into.ts +21 -0
  101. package/src/rust-ffi/options.ts +113 -0
  102. package/src/rust-ffi/packed.ts +253 -0
  103. package/src/rust-ffi/proven.ts +28 -0
  104. package/src/rust-ffi/scalar/crypto.ts +346 -0
  105. package/src/rust-ffi/scalar/factories.ts +459 -0
  106. package/src/rust-ffi/scalar/hashing.ts +74 -0
  107. package/src/rust-ffi/scalar/http.ts +337 -0
  108. package/src/rust-ffi/scalar/index.ts +31 -0
  109. package/src/rust-ffi/scalar/interface.ts +325 -0
  110. package/src/rust-ffi/scalar/json-packed.ts +175 -0
  111. package/src/rust-ffi/scalar/json.ts +61 -0
  112. package/src/rust-ffi/scalar/payload.ts +241 -0
  113. package/src/rust-ffi/text.ts +121 -0
  114. package/src/selection.json +194 -0
  115. package/src/selection.ts +73 -0
  116. package/src/shared/adaptive.ts +67 -0
  117. package/src/shared/buffer-pool.ts +264 -0
  118. package/src/shared/bytes.ts +108 -9
  119. package/src/shared/codec.ts +78 -0
  120. package/src/shared/env.ts +20 -0
  121. package/src/shared/log.ts +75 -0
  122. package/src/shared/metrics.ts +247 -0
  123. package/src/shared/packed/index.ts +10 -0
  124. package/src/shared/packed/parsers.ts +31 -0
  125. package/src/shared/packed/schema.ts +23 -0
  126. package/src/shared/packed/wire.ts +504 -0
  127. package/src/shared/proven.ts +289 -0
  128. package/src/shared/request-id.ts +67 -0
  129. package/src/shared/response.ts +104 -0
  130. package/src/shared/runtime.ts +29 -0
  131. package/src/shared/trace.ts +81 -0
  132. package/src/shared/uuid.ts +15 -0
  133. package/Cargo.toml +0 -73
  134. package/bench.ts +0 -3
  135. package/rust/batch.rs +0 -195
  136. package/rust/cookie_parser.rs +0 -70
  137. package/rust/cors.rs +0 -263
  138. package/rust/hashing.rs +0 -164
  139. package/rust/headers.rs +0 -234
  140. package/rust/hmac_sha256.rs +0 -113
  141. package/rust/http_parser.rs +0 -132
  142. package/rust/ingress.rs +0 -616
  143. package/rust/ingress_constants.rs +0 -89
  144. package/rust/ip_trust.rs +0 -185
  145. package/rust/json_ops.rs +0 -66
  146. package/rust/json_patch_ops.rs +0 -25
  147. package/rust/json_schema.rs +0 -151
  148. package/rust/json_ser.rs +0 -429
  149. package/rust/lib.rs +0 -48
  150. package/rust/method.rs +0 -141
  151. package/rust/mime_lookup.rs +0 -76
  152. package/rust/output.rs +0 -238
  153. package/rust/proxy.rs +0 -90
  154. package/rust/query_parser.rs +0 -141
  155. package/rust/random_token.rs +0 -52
  156. package/rust/rate_limit.rs +0 -203
  157. package/rust/terminal.rs +0 -95
  158. package/rust/unit_tests.rs +0 -843
  159. package/rust/url_codec.rs +0 -133
  160. package/rust/util.rs +0 -537
  161. package/rust/validation.rs +0 -107
  162. package/rust/websocket.rs +0 -23
  163. package/src/baseline/index.ts +0 -12
  164. package/src/baseline/tasks/cookie.ts +0 -22
  165. package/src/baseline/tasks/hashing.ts +0 -18
  166. package/src/baseline/tasks/hmac.ts +0 -38
  167. package/src/baseline/tasks/http.ts +0 -62
  168. package/src/baseline/tasks/json-patch.ts +0 -12
  169. package/src/baseline/tasks/json.ts +0 -50
  170. package/src/baseline/tasks/mime.ts +0 -5
  171. package/src/baseline/tasks/query.ts +0 -14
  172. package/src/baseline/tasks/token.ts +0 -15
  173. package/src/baseline/tasks/url.ts +0 -11
  174. package/src/baseline/tasks/validation.ts +0 -19
  175. package/src/baseline/tasks/websocket.ts +0 -14
  176. package/src/bench/assert.ts +0 -70
  177. package/src/bench/checks.ts +0 -227
  178. package/src/bench/checksum.ts +0 -27
  179. package/src/bench/comparisons.ts +0 -70
  180. package/src/bench/concurrent-worker.ts +0 -135
  181. package/src/bench/fixtures.ts +0 -233
  182. package/src/bench/index.ts +0 -2
  183. package/src/bench/measure.ts +0 -177
  184. package/src/bench/now.ts +0 -3
  185. package/src/bench/report.ts +0 -79
  186. package/src/bench/run.ts +0 -57
  187. package/src/bench/tasks/complex.ts +0 -232
  188. package/src/bench/tasks/concurrent.ts +0 -213
  189. package/src/bench/tasks/cookie.ts +0 -44
  190. package/src/bench/tasks/hashing.ts +0 -33
  191. package/src/bench/tasks/hmac.ts +0 -36
  192. package/src/bench/tasks/http.ts +0 -50
  193. package/src/bench/tasks/index.ts +0 -52
  194. package/src/bench/tasks/json-patch.ts +0 -21
  195. package/src/bench/tasks/json.ts +0 -33
  196. package/src/bench/tasks/mime.ts +0 -21
  197. package/src/bench/tasks/query.ts +0 -44
  198. package/src/bench/tasks/stress.ts +0 -142
  199. package/src/bench/tasks/token.ts +0 -20
  200. package/src/bench/tasks/url.ts +0 -34
  201. package/src/bench/tasks/validation.ts +0 -57
  202. package/src/bench/tasks/websocket.ts +0 -21
  203. package/src/bench/types.ts +0 -60
  204. package/src/data/json-rows.ts +0 -33
  205. package/src/ingress/packed-input.ts +0 -59
  206. package/src/shared/json.ts +0 -18
  207. package/src/shared/packed.ts +0 -316
@@ -1,213 +0,0 @@
1
- import type { BenchFixtures, ComplexFixtures } from "../fixtures";
2
- import type { ConcurrentBenchTask } from "../types";
3
-
4
- export function concurrentTasks(
5
- f: BenchFixtures,
6
- c: ComplexFixtures,
7
- ): ConcurrentBenchTask[] {
8
- return [
9
- // ── JSON validation: medium concurrency ──
10
- {
11
- name: "native:json_valid_concurrent_10",
12
- op: "native:json_valid",
13
- payload: f.jsonPayload,
14
- concurrency: 10,
15
- iterationsPerSlot: 50,
16
- warmupPerSlot: 5,
17
- },
18
- {
19
- name: "rust:json_valid_concurrent_10",
20
- op: "rust:json_valid",
21
- payload: f.jsonPayload,
22
- concurrency: 10,
23
- iterationsPerSlot: 50,
24
- warmupPerSlot: 5,
25
- },
26
-
27
- // ── JSON validation: high concurrency ──
28
- {
29
- name: "native:json_valid_concurrent_50",
30
- op: "native:json_valid",
31
- payload: f.jsonPayload,
32
- concurrency: 50,
33
- iterationsPerSlot: 20,
34
- warmupPerSlot: 2,
35
- },
36
- {
37
- name: "rust:json_valid_concurrent_50",
38
- op: "rust:json_valid",
39
- payload: f.jsonPayload,
40
- concurrency: 50,
41
- iterationsPerSlot: 20,
42
- warmupPerSlot: 2,
43
- },
44
-
45
- // ── HTTP parse burst ──
46
- {
47
- name: "native:http_parse_concurrent_20",
48
- op: "native:http_parse",
49
- payload: f.httpRaw,
50
- concurrency: 20,
51
- iterationsPerSlot: 50,
52
- warmupPerSlot: 5,
53
- },
54
- {
55
- name: "rust:http_parse_concurrent_20",
56
- op: "rust:http_parse",
57
- payload: f.httpRaw,
58
- concurrency: 20,
59
- iterationsPerSlot: 50,
60
- warmupPerSlot: 5,
61
- },
62
-
63
- // ── HMAC burst ──
64
- {
65
- name: "native:hmac_sha256_concurrent_20",
66
- op: "native:hmac_sha256",
67
- payload: {
68
- key: f.hmacKey,
69
- data: f.hmacData,
70
- },
71
- concurrency: 20,
72
- iterationsPerSlot: 30,
73
- warmupPerSlot: 5,
74
- },
75
- {
76
- name: "rust:hmac_sha256_concurrent_20",
77
- op: "rust:hmac_sha256",
78
- payload: {
79
- key: f.hmacKey,
80
- data: f.hmacData,
81
- },
82
- concurrency: 20,
83
- iterationsPerSlot: 30,
84
- warmupPerSlot: 5,
85
- },
86
-
87
- // ── Validation burst: email ──
88
- {
89
- name: "native:validate_email_concurrent_50",
90
- op: "native:validate_email",
91
- payload: f.emailOk,
92
- concurrency: 50,
93
- iterationsPerSlot: 40,
94
- warmupPerSlot: 5,
95
- },
96
- {
97
- name: "rust:validate_email_concurrent_50",
98
- op: "rust:validate_email",
99
- payload: f.emailOk,
100
- concurrency: 50,
101
- iterationsPerSlot: 40,
102
- warmupPerSlot: 5,
103
- },
104
-
105
- // ── Validation burst: uuid ──
106
- {
107
- name: "native:validate_uuid_concurrent_50",
108
- op: "native:validate_uuid",
109
- payload: f.uuidOk,
110
- concurrency: 50,
111
- iterationsPerSlot: 40,
112
- warmupPerSlot: 5,
113
- },
114
- {
115
- name: "rust:validate_uuid_concurrent_50",
116
- op: "rust:validate_uuid",
117
- payload: f.uuidOk,
118
- concurrency: 50,
119
- iterationsPerSlot: 40,
120
- warmupPerSlot: 5,
121
- },
122
-
123
- // ── Query parse burst ──
124
- {
125
- name: "native:query_parse_concurrent_20",
126
- op: "native:query_parse",
127
- payload: f.queryStr,
128
- concurrency: 20,
129
- iterationsPerSlot: 50,
130
- warmupPerSlot: 5,
131
- },
132
- {
133
- name: "rust:query_parse_concurrent_20",
134
- op: "rust:query_parse",
135
- payload: f.queryStr,
136
- concurrency: 20,
137
- iterationsPerSlot: 50,
138
- warmupPerSlot: 5,
139
- },
140
-
141
- // ── Cookie parse burst ──
142
- {
143
- name: "native:cookie_parse_concurrent_20",
144
- op: "native:cookie_parse",
145
- payload: f.cookieStr,
146
- concurrency: 20,
147
- iterationsPerSlot: 50,
148
- warmupPerSlot: 5,
149
- },
150
- {
151
- name: "rust:cookie_parse_concurrent_20",
152
- op: "rust:cookie_parse",
153
- payload: f.cookieStr,
154
- concurrency: 20,
155
- iterationsPerSlot: 50,
156
- warmupPerSlot: 5,
157
- },
158
-
159
- // ── CRC32 burst ──
160
- {
161
- name: "native:crc32_concurrent_20",
162
- op: "native:crc32",
163
- payload: f.crcInput,
164
- concurrency: 20,
165
- iterationsPerSlot: 100,
166
- warmupPerSlot: 10,
167
- },
168
- {
169
- name: "rust:crc32_concurrent_20",
170
- op: "rust:crc32",
171
- payload: f.crcInput,
172
- concurrency: 20,
173
- iterationsPerSlot: 100,
174
- warmupPerSlot: 10,
175
- },
176
-
177
- // ── JSON sum burst ──
178
- {
179
- name: "native:json_sum_concurrent_20",
180
- op: "native:json_sum",
181
- payload: f.jsonPayload,
182
- concurrency: 20,
183
- iterationsPerSlot: 20,
184
- warmupPerSlot: 3,
185
- },
186
- {
187
- name: "rust:json_sum_concurrent_20",
188
- op: "rust:json_sum",
189
- payload: f.jsonPayload,
190
- concurrency: 20,
191
- iterationsPerSlot: 20,
192
- warmupPerSlot: 3,
193
- },
194
-
195
- // ── Batch JSON validation burst ──
196
- {
197
- name: "native:json_valid_batch_concurrent_10",
198
- op: "native:json_valid_batch",
199
- payload: c.batchJsonDocs,
200
- concurrency: 10,
201
- iterationsPerSlot: 20,
202
- warmupPerSlot: 3,
203
- },
204
- {
205
- name: "rust:json_valid_batch_concurrent_10",
206
- op: "rust:json_valid_batch_packed",
207
- payload: c.batchJsonDocs,
208
- concurrency: 10,
209
- iterationsPerSlot: 20,
210
- warmupPerSlot: 3,
211
- },
212
- ];
213
- }
@@ -1,44 +0,0 @@
1
- import * as native from "../../baseline";
2
- import { rust } from "../../rust-ffi";
3
- import { pairsToObject, readPairsPacked } from "../../shared/packed";
4
- import type { BenchFixtures } from "../fixtures";
5
- import type { BenchTask } from "../types";
6
-
7
- export function cookieTasks(f: BenchFixtures): BenchTask[] {
8
- return [
9
- {
10
- name: "native:cookie_parse",
11
- run: () => native.nativeCookieParsePacked(f.cookieStr).byteLength,
12
- iterations: 500,
13
- warmup: 50,
14
- },
15
- {
16
- name: "rust:cookie_parse",
17
- run: () => rust.cookieParsePacked(f.cookieStr).byteLength,
18
- iterations: 500,
19
- warmup: 50,
20
- },
21
- {
22
- name: "native:cookie_parse_pipeline",
23
- run: () => {
24
- const obj = pairsToObject(
25
- readPairsPacked(native.nativeCookieParsePacked(f.cookieStr)),
26
- );
27
- return Object.keys(obj).length;
28
- },
29
- iterations: 300,
30
- warmup: 30,
31
- },
32
- {
33
- name: "rust:cookie_parse_pipeline",
34
- run: () => {
35
- const obj = pairsToObject(
36
- readPairsPacked(rust.cookieParsePacked(f.cookieStr)),
37
- );
38
- return Object.keys(obj).length;
39
- },
40
- iterations: 300,
41
- warmup: 30,
42
- },
43
- ];
44
- }
@@ -1,33 +0,0 @@
1
- import * as native from "../../baseline";
2
- import { rust } from "../../rust-ffi";
3
- import type { BenchFixtures } from "../fixtures";
4
- import type { BenchTask } from "../types";
5
-
6
- export function hashingTasks(f: BenchFixtures): BenchTask[] {
7
- return [
8
- {
9
- name: "native:crc32",
10
- run: () => native.nativeCrc32(f.crcInput),
11
- iterations: 1000,
12
- warmup: 100,
13
- },
14
- {
15
- name: "rust:crc32",
16
- run: () => rust.crc32(f.crcInput),
17
- iterations: 1000,
18
- warmup: 100,
19
- },
20
- {
21
- name: "native:fnv1a64",
22
- run: () => native.nativeFnv1a64(f.crcInput),
23
- iterations: 1000,
24
- warmup: 100,
25
- },
26
- {
27
- name: "rust:fnv1a64",
28
- run: () => rust.fnv1a64(f.crcInput),
29
- iterations: 1000,
30
- warmup: 100,
31
- },
32
- ];
33
- }
@@ -1,36 +0,0 @@
1
- import * as native from "../../baseline";
2
- import { rust } from "../../rust-ffi";
3
- import type { BenchFixtures } from "../fixtures";
4
- import type { BenchTask } from "../types";
5
-
6
- export function hmacTasks(f: BenchFixtures): BenchTask[] {
7
- return [
8
- {
9
- name: "native:hmac_sha256",
10
- run: () => native.nativeHmacSha256(f.hmacKey, f.hmacData).byteLength,
11
- iterations: 500,
12
- warmup: 50,
13
- },
14
- {
15
- name: "rust:hmac_sha256",
16
- run: () => rust.hmacSha256(f.hmacKey, f.hmacData).byteLength,
17
- iterations: 500,
18
- warmup: 50,
19
- },
20
- {
21
- name: "native:hmac_verify",
22
- run: () =>
23
- native.nativeHmacSha256Verify(f.hmacKey, f.hmacData, f.hmacSig)
24
- ? 1
25
- : 0,
26
- iterations: 500,
27
- warmup: 50,
28
- },
29
- {
30
- name: "rust:hmac_verify",
31
- run: () => rust.hmacSha256Verify(f.hmacKey, f.hmacData, f.hmacSig),
32
- iterations: 500,
33
- warmup: 50,
34
- },
35
- ];
36
- }
@@ -1,50 +0,0 @@
1
- import * as native from "../../baseline";
2
- import { rust } from "../../rust-ffi";
3
- import { readHttpPacked } from "../../shared/packed";
4
- import type { BenchFixtures } from "../fixtures";
5
- import type { BenchTask } from "../types";
6
-
7
- export function httpTasks(f: BenchFixtures): BenchTask[] {
8
- return [
9
- {
10
- name: "native:http_parse",
11
- run: () => native.nativeHttpParseRequestPacked(f.httpRaw).byteLength,
12
- iterations: 500,
13
- warmup: 50,
14
- },
15
- {
16
- name: "rust:http_parse",
17
- run: () => rust.httpParseRequestPacked(f.httpRaw).byteLength,
18
- iterations: 500,
19
- warmup: 50,
20
- },
21
- {
22
- name: "native:http_parse_pipeline",
23
- run: () => {
24
- const parsed = readHttpPacked(
25
- native.nativeHttpParseRequestPacked(f.httpRaw),
26
- );
27
- return (
28
- parsed.method.length +
29
- parsed.path.length +
30
- Object.keys(parsed.headers).length
31
- );
32
- },
33
- iterations: 300,
34
- warmup: 30,
35
- },
36
- {
37
- name: "rust:http_parse_pipeline",
38
- run: () => {
39
- const parsed = readHttpPacked(rust.httpParseRequestPacked(f.httpRaw));
40
- return (
41
- parsed.method.length +
42
- parsed.path.length +
43
- Object.keys(parsed.headers).length
44
- );
45
- },
46
- iterations: 300,
47
- warmup: 30,
48
- },
49
- ];
50
- }
@@ -1,52 +0,0 @@
1
- import type { BenchFixtures, ComplexFixtures } from "../fixtures";
2
- import type { BenchTask, ConcurrentBenchTask, StressBenchTask } from "../types";
3
- import { cookieTasks } from "./cookie";
4
- import { concurrentTasks } from "./concurrent";
5
- import { complexTasks } from "./complex";
6
- import { hashingTasks } from "./hashing";
7
- import { hmacTasks } from "./hmac";
8
- import { httpTasks } from "./http";
9
- import { jsonTasks } from "./json";
10
- import { jsonPatchTasks } from "./json-patch";
11
- import { mimeTasks } from "./mime";
12
- import { queryTasks } from "./query";
13
- import { stressTasks } from "./stress";
14
- import { tokenTasks } from "./token";
15
- import { urlTasks } from "./url";
16
- import { validationTasks } from "./validation";
17
- import { websocketTasks } from "./websocket";
18
-
19
- export function createAllTasks(fixtures: BenchFixtures): BenchTask[] {
20
- return [
21
- ...jsonTasks(fixtures),
22
- ...httpTasks(fixtures),
23
- ...queryTasks(fixtures),
24
- ...cookieTasks(fixtures),
25
- ...tokenTasks(),
26
- ...websocketTasks(fixtures),
27
- ...jsonPatchTasks(fixtures),
28
- ...hmacTasks(fixtures),
29
- ...validationTasks(fixtures),
30
- ...hashingTasks(fixtures),
31
- ...mimeTasks(fixtures),
32
- ...urlTasks(fixtures),
33
- ];
34
- }
35
-
36
- export function createComplexTasks(fixtures: ComplexFixtures): BenchTask[] {
37
- return complexTasks(fixtures);
38
- }
39
-
40
- export function createConcurrentTasks(
41
- fixtures: BenchFixtures,
42
- complex: ComplexFixtures,
43
- ): ConcurrentBenchTask[] {
44
- return concurrentTasks(fixtures, complex);
45
- }
46
-
47
- export function createStressTasks(
48
- fixtures: BenchFixtures,
49
- complex: ComplexFixtures,
50
- ): StressBenchTask[] {
51
- return stressTasks(fixtures, complex);
52
- }
@@ -1,21 +0,0 @@
1
- import * as native from "../../baseline";
2
- import { rust } from "../../rust-ffi";
3
- import type { BenchFixtures } from "../fixtures";
4
- import type { BenchTask } from "../types";
5
-
6
- export function jsonPatchTasks(f: BenchFixtures): BenchTask[] {
7
- return [
8
- {
9
- name: "native:json_patch",
10
- run: () => native.nativeJsonPatch(f.jsonDoc, f.jsonPatch).byteLength,
11
- iterations: 500,
12
- warmup: 50,
13
- },
14
- {
15
- name: "rust:json_patch",
16
- run: () => rust.jsonPatch(f.jsonDoc, f.jsonPatch).byteLength,
17
- iterations: 500,
18
- warmup: 50,
19
- },
20
- ];
21
- }
@@ -1,33 +0,0 @@
1
- import * as native from "../../baseline";
2
- import { rust } from "../../rust-ffi";
3
- import type { BenchFixtures } from "../fixtures";
4
- import type { BenchTask } from "../types";
5
-
6
- export function jsonTasks(f: BenchFixtures): BenchTask[] {
7
- return [
8
- {
9
- name: "native:json_valid",
10
- run: () => native.nativeJsonValid(f.jsonPayload),
11
- iterations: 100,
12
- warmup: 10,
13
- },
14
- {
15
- name: "rust:json_valid",
16
- run: () => rust.jsonValid(f.jsonPayload),
17
- iterations: 100,
18
- warmup: 10,
19
- },
20
- {
21
- name: "native:json_sum",
22
- run: () => native.nativeJsonSum(f.jsonPayload),
23
- iterations: 100,
24
- warmup: 10,
25
- },
26
- {
27
- name: "rust:json_sum",
28
- run: () => rust.jsonSumIds(f.jsonPayload),
29
- iterations: 100,
30
- warmup: 10,
31
- },
32
- ];
33
- }
@@ -1,21 +0,0 @@
1
- import * as native from "../../baseline";
2
- import { rust } from "../../rust-ffi";
3
- import type { BenchFixtures } from "../fixtures";
4
- import type { BenchTask } from "../types";
5
-
6
- export function mimeTasks(f: BenchFixtures): BenchTask[] {
7
- return [
8
- {
9
- name: "native:mime",
10
- run: () => native.nativeMimeFromExtension("json").length,
11
- iterations: 1000,
12
- warmup: 100,
13
- },
14
- {
15
- name: "rust:mime",
16
- run: () => rust.mimeFromExtension(f.mimeExt).byteLength,
17
- iterations: 1000,
18
- warmup: 100,
19
- },
20
- ];
21
- }
@@ -1,44 +0,0 @@
1
- import * as native from "../../baseline";
2
- import { rust } from "../../rust-ffi";
3
- import { pairsToObject, readPairsPacked } from "../../shared/packed";
4
- import type { BenchFixtures } from "../fixtures";
5
- import type { BenchTask } from "../types";
6
-
7
- export function queryTasks(f: BenchFixtures): BenchTask[] {
8
- return [
9
- {
10
- name: "native:query_parse",
11
- run: () => native.nativeQueryParsePacked(f.queryStr).byteLength,
12
- iterations: 500,
13
- warmup: 50,
14
- },
15
- {
16
- name: "rust:query_parse",
17
- run: () => rust.queryParsePacked(f.queryStr).byteLength,
18
- iterations: 500,
19
- warmup: 50,
20
- },
21
- {
22
- name: "native:query_parse_pipeline",
23
- run: () => {
24
- const obj = pairsToObject(
25
- readPairsPacked(native.nativeQueryParsePacked(f.queryStr)),
26
- );
27
- return Object.keys(obj).length;
28
- },
29
- iterations: 300,
30
- warmup: 30,
31
- },
32
- {
33
- name: "rust:query_parse_pipeline",
34
- run: () => {
35
- const obj = pairsToObject(
36
- readPairsPacked(rust.queryParsePacked(f.queryStr)),
37
- );
38
- return Object.keys(obj).length;
39
- },
40
- iterations: 300,
41
- warmup: 30,
42
- },
43
- ];
44
- }
@@ -1,142 +0,0 @@
1
- import * as native from "../../baseline";
2
- import { rust } from "../../rust-ffi";
3
- import type { BenchFixtures, ComplexFixtures } from "../fixtures";
4
- import type { StressBenchTask } from "../types";
5
-
6
- export function stressTasks(
7
- f: BenchFixtures,
8
- _c: ComplexFixtures,
9
- ): StressBenchTask[] {
10
- return [
11
- // ── JSON validation stress ──
12
- {
13
- name: "native:json_valid_stress",
14
- run: () => native.nativeJsonValid(f.jsonPayload),
15
- durationMs: 2000,
16
- warmupMs: 200,
17
- },
18
- {
19
- name: "rust:json_valid_stress",
20
- run: () => rust.jsonValid(f.jsonPayload),
21
- durationMs: 2000,
22
- warmupMs: 200,
23
- },
24
- // ── JSON sum stress ──
25
- {
26
- name: "native:json_sum_stress",
27
- run: () => native.nativeJsonSum(f.jsonPayload),
28
- durationMs: 2000,
29
- warmupMs: 200,
30
- },
31
- {
32
- name: "rust:json_sum_stress",
33
- run: () => rust.jsonSumIds(f.jsonPayload),
34
- durationMs: 2000,
35
- warmupMs: 200,
36
- },
37
- // ── HTTP parse stress ──
38
- {
39
- name: "native:http_parse_stress",
40
- run: () => native.nativeHttpParseRequestPacked(f.httpRaw).byteLength,
41
- durationMs: 2000,
42
- warmupMs: 200,
43
- },
44
- {
45
- name: "rust:http_parse_stress",
46
- run: () => rust.httpParseRequestPacked(f.httpRaw).byteLength,
47
- durationMs: 2000,
48
- warmupMs: 200,
49
- },
50
- // ── HMAC stress ──
51
- {
52
- name: "native:hmac_sha256_stress",
53
- run: () => native.nativeHmacSha256(f.hmacKey, f.hmacData).byteLength,
54
- durationMs: 2000,
55
- warmupMs: 200,
56
- },
57
- {
58
- name: "rust:hmac_sha256_stress",
59
- run: () => rust.hmacSha256(f.hmacKey, f.hmacData).byteLength,
60
- durationMs: 2000,
61
- warmupMs: 200,
62
- },
63
- // ── CRC32 stress ──
64
- {
65
- name: "native:crc32_stress",
66
- run: () => native.nativeCrc32(f.crcInput),
67
- durationMs: 2000,
68
- warmupMs: 200,
69
- },
70
- {
71
- name: "rust:crc32_stress",
72
- run: () => rust.crc32(f.crcInput),
73
- durationMs: 2000,
74
- warmupMs: 200,
75
- },
76
- // ── Query parse stress ──
77
- {
78
- name: "native:query_parse_stress",
79
- run: () => native.nativeQueryParsePacked(f.queryStr).byteLength,
80
- durationMs: 2000,
81
- warmupMs: 200,
82
- },
83
- {
84
- name: "rust:query_parse_stress",
85
- run: () => rust.queryParsePacked(f.queryStr).byteLength,
86
- durationMs: 2000,
87
- warmupMs: 200,
88
- },
89
- // ── Email validation stress ──
90
- {
91
- name: "native:validate_email_stress",
92
- run: () => (native.nativeValidateEmail(f.emailOk) ? 1 : 0),
93
- durationMs: 2000,
94
- warmupMs: 200,
95
- },
96
- {
97
- name: "rust:validate_email_stress",
98
- run: () => rust.validateEmail(f.emailOk),
99
- durationMs: 2000,
100
- warmupMs: 200,
101
- },
102
- // ── UUID validation stress ──
103
- {
104
- name: "native:validate_uuid_stress",
105
- run: () => (native.nativeValidateUuid(f.uuidOk) ? 1 : 0),
106
- durationMs: 2000,
107
- warmupMs: 200,
108
- },
109
- {
110
- name: "rust:validate_uuid_stress",
111
- run: () => rust.validateUuid(f.uuidOk),
112
- durationMs: 2000,
113
- warmupMs: 200,
114
- },
115
- // ── Cookie parse stress ──
116
- {
117
- name: "native:cookie_parse_stress",
118
- run: () => native.nativeCookieParsePacked(f.cookieStr).byteLength,
119
- durationMs: 2000,
120
- warmupMs: 200,
121
- },
122
- {
123
- name: "rust:cookie_parse_stress",
124
- run: () => rust.cookieParsePacked(f.cookieStr).byteLength,
125
- durationMs: 2000,
126
- warmupMs: 200,
127
- },
128
- // ── WebSocket accept stress ──
129
- {
130
- name: "native:ws_accept_key_stress",
131
- run: () => native.nativeWsAcceptKey(f.wsKey).byteLength,
132
- durationMs: 2000,
133
- warmupMs: 200,
134
- },
135
- {
136
- name: "rust:ws_accept_key_stress",
137
- run: () => rust.wsAcceptKey(f.wsKeyBytes).byteLength,
138
- durationMs: 2000,
139
- warmupMs: 200,
140
- },
141
- ];
142
- }