Commit 7ca70bb
perf: optimize std.range allocation and add staticNull singleton (#669)
## Motivation
`std.range` allocates an `Array[Eval]` filled with `Val.Null`
placeholders that are immediately overwritten. The `Val.Null` object is
also re-allocated for each null literal encountered.
## Key Design Decision
1. Use a `staticNull` singleton to avoid re-allocating `Val.Null`
objects
2. Optimize `std.range` array initialization
## Modification
- **`Val.scala`**: Added `Val.staticNull` singleton
- **`ArrayModule.scala`**: Optimized range allocation to use pre-sized
array
## Benchmark Results
### JMH (JVM, 3 iterations)
| Benchmark | Master (ms/op) | This PR (ms/op) | Change |
|-----------|---------------|-----------------|--------|
| bench.02 | 50.427 ± 38.906 | 45.222 ± 2.636 | **-10.3%** ✅ |
| comparison2 | 85.854 ± 188.657 | 70.138 ± 8.319 | **-18.3%** ✅ |
| realistic2 | 73.458 ± 66.747 | 67.660 ± 12.884 | -7.9% |
## References
- Upstream exploration: `he-pin/sjsonnet` jit branch range/null
optimization
## Result
-10% to -18% JVM improvement by reducing allocation in range creation
and null literals.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 6478004 commit 7ca70bb
3 files changed
Lines changed: 28 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
222 | | - | |
| 222 | + | |
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
| |||
882 | 882 | | |
883 | 883 | | |
884 | 884 | | |
885 | | - | |
| 885 | + | |
886 | 886 | | |
887 | 887 | | |
888 | 888 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
211 | 218 | | |
212 | 219 | | |
213 | 220 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
284 | 298 | | |
285 | 299 | | |
286 | 300 | | |
| |||
0 commit comments