Commit cfbb1a1
authored
perf: array comparison reference equality + numeric fast path (#674)
## Motivation
Array comparison in the evaluator compares element-by-element. Two
optimizations are possible:
1. If both arrays are the same object (reference equality), they are
trivially equal
2. For numeric elements (the most common comparison type), a direct
double comparison is faster than full `Val` dispatch
## Key Design Decision
Add reference equality short-circuit and inline numeric comparison fast
path in the array comparison loop.
## Modification
- **`Evaluator.scala`**: Added reference equality check for arrays,
inline numeric fast path for element comparison
## Benchmark Results
### JMH (JVM, 3 iterations)
| Benchmark | Master (ms/op) | This PR (ms/op) | Change |
|-----------|---------------|-----------------|--------|
| bench.02 | 50.427 ± 38.906 | 46.361 ± 6.238 | **-8.1%** ✅ |
| comparison2 | 85.854 ± 188.657 | 70.597 ± 22.435 | **-17.8%** ✅ |
| realistic2 | 73.458 ± 66.747 | 64.775 ± 1.436 | **-11.8%** ✅ |
## References
- Upstream exploration: `he-pin/sjsonnet` jit branch array comparison
optimization
## Result
-8% to -18% JVM improvement for array comparison via reference equality
short-circuit and numeric fast path.1 parent 7bb4b6d commit cfbb1a1
1 file changed
Lines changed: 16 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1191 | 1191 | | |
1192 | 1192 | | |
1193 | 1193 | | |
1194 | | - | |
1195 | | - | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
1196 | 1209 | | |
1197 | 1210 | | |
1198 | | - | |
| 1211 | + | |
1199 | 1212 | | |
1200 | 1213 | | |
1201 | 1214 | | |
| |||
0 commit comments