Commit 6fa79e6
⚡ Optimize SQL params allocation (#74)
* Optimize `SQL::params` to avoid string allocation for integers
- Introduce `D1Value` enum in `common/src/d1.rs` to hold parameter values without allocation (using `Cow<'a, str>` for strings and `i64/f64` for numbers).
- Update `SQL::params` to return `Vec<D1Value>` instead of generic `Vec<T>`.
- Update `native/src/d1.rs` to use `Vec<D1Value>` in `QueryBody` for serialization.
- Update `worker/src/d1.rs` to map `Vec<D1Value>` to `Vec<JsValue>` for Cloudflare D1 binding, avoiding string conversion for integers.
- Measured ~3.27x improvement (435ms -> 133ms) in parameter generation benchmark.
Co-authored-by: Asutorufa <16442314+Asutorufa@users.noreply.github.com>
* Optimize `SQL::params` to avoid string allocation for integers (PR feedback addressed)
- Updated `From<u64>` for `D1Value` to saturate at `i64::MAX` to prevent negative wrapping, addressing PR feedback.
- Introduce `D1Value` enum in `common/src/d1.rs` to hold parameter values without allocation.
- Update `SQL::params` to return `Vec<D1Value>`.
- Update `native/src/d1.rs` and `worker/src/d1.rs` to support `D1Value`.
- Verified performance improvement (~3.27x).
Co-authored-by: Asutorufa <16442314+Asutorufa@users.noreply.github.com>
* Optimize `SQL::params` to avoid string allocation for integers (PR feedback addressed)
- Updated `native/src/d1.rs` to extract `sql.sql()` and `sql.params()` to local variables to avoid redundant allocation.
- Updated `From<u64>` for `D1Value` to saturate at `i64::MAX`.
- Introduce `D1Value` enum in `common/src/d1.rs`.
- Update `SQL::params` to return `Vec<D1Value>`.
- Update `native/src/d1.rs` and `worker/src/d1.rs` to support `D1Value`.
- Verified performance improvement (~3.27x).
Co-authored-by: Asutorufa <16442314+Asutorufa@users.noreply.github.com>
---------
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>1 parent 61c94af commit 6fa79e6
3 files changed
+93
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
207 | 263 | | |
208 | 264 | | |
209 | 265 | | |
| |||
325 | 381 | | |
326 | 382 | | |
327 | 383 | | |
328 | | - | |
| 384 | + | |
329 | 385 | | |
330 | 386 | | |
331 | 387 | | |
332 | 388 | | |
333 | 389 | | |
334 | | - | |
| 390 | + | |
335 | 391 | | |
336 | 392 | | |
337 | 393 | | |
338 | 394 | | |
339 | 395 | | |
340 | 396 | | |
341 | | - | |
| 397 | + | |
342 | 398 | | |
343 | 399 | | |
344 | 400 | | |
| |||
354 | 410 | | |
355 | 411 | | |
356 | 412 | | |
357 | | - | |
358 | | - | |
359 | | - | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
360 | 416 | | |
361 | 417 | | |
362 | | - | |
| 418 | + | |
363 | 419 | | |
364 | 420 | | |
365 | 421 | | |
366 | | - | |
| 422 | + | |
367 | 423 | | |
368 | 424 | | |
369 | 425 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
| 13 | + | |
| 14 | + | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
144 | 147 | | |
145 | 148 | | |
146 | | - | |
147 | | - | |
| 149 | + | |
| 150 | + | |
148 | 151 | | |
149 | 152 | | |
150 | 153 | | |
151 | | - | |
152 | | - | |
| 154 | + | |
| 155 | + | |
153 | 156 | | |
154 | 157 | | |
155 | 158 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
46 | 61 | | |
47 | 62 | | |
48 | 63 | | |
49 | | - | |
| 64 | + | |
50 | 65 | | |
51 | 66 | | |
52 | 67 | | |
| |||
62 | 77 | | |
63 | 78 | | |
64 | 79 | | |
65 | | - | |
| 80 | + | |
66 | 81 | | |
67 | 82 | | |
68 | 83 | | |
| |||
0 commit comments