Commit dd4f1c3
committed
perf: Num fast path for std.member array search
Motivation:
std.member on arrays called ev.equal() for every element, incurring
reference equality check + isInstanceOf[Val.Func] + full pattern match
dispatch per comparison. For numeric arrays (the common case in
benchmarks like go_suite/member.jsonnet), this is pure overhead.
Modification:
- Hoist x.value outside the loop to avoid repeated Eval forcing
- Add Num fast path: when the search target is Val.Num, compare doubles
directly via isInstanceOf[Val.Num] + asDouble, bypassing equal()
- General path unchanged for non-Num targets
Result:
member benchmark: from 1.97x slower to 1.04x faster than jrsonnet.
All 80 test suites pass. Collateral improvement on benchmarks that use
array equality internally (manifestJsonEx 2.51x→1.51x, setDiff
1.70x→1.43x, parseInt 1.36x→1.14x).1 parent 8e8f928 commit dd4f1c3
1 file changed
Lines changed: 23 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
585 | 585 | | |
586 | 586 | | |
587 | 587 | | |
588 | | - | |
589 | | - | |
590 | | - | |
591 | | - | |
592 | | - | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
593 | 611 | | |
594 | | - | |
595 | 612 | | |
596 | 613 | | |
597 | 614 | | |
| |||
0 commit comments