perf: avoid the intermediate array in from_entries (#3626)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Define `from_entries` as `add(.[] | f) // {}` instead of `map(f) | add // {}`. Since `add(f)` is `reduce f as $x (null; . + $x)`, both fold the same values in the same order from the same seed, so the only difference is that the array of single-key objects built by `map` is never materialized. Measured with both the generator and the result suppressed, so that only the `from_entries` work differs: 6-15% less user time across input shapes, which is 10-24% of what `from_entries` itself costs. For inputs above roughly a thousand entries, peak RSS drops by 37%, around 80% of the memory `from_entries` adds on top of its input; a 1,000,000 entry array goes from 1064 MiB to 672 MiB.
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+2 added−2 removed
- other:+2 added−2 removed