Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next-gen group_by #129

Merged
merged 3 commits into from
Jan 9, 2024
Merged

Next-gen group_by #129

merged 3 commits into from
Jan 9, 2024

Conversation

01mf02
Copy link
Owner

@01mf02 01mf02 commented Nov 21, 2023

This rewrites group_by to 1) terminate as soon as an error is encountered and to 2) remove the dependency on itertools.

The runtime of group_by slightly increases by about 4%:

$ hyperfine -L jq ./jaq-before,target/release/jaq,./jq-linux-amd64-1.7 '{jq} -n "[range(0; 1000000)] | group_by(. % 2) | empty"'
Benchmark 1: ./jaq-before -n "[range(0; 1000000)] | group_by(. % 2) | empty"
  Time (mean ± σ):     492.0 ms ±   2.4 ms    [User: 411.1 ms, System: 80.6 ms]
  Range (min … max):   487.0 ms … 494.9 ms    10 runs
 
Benchmark 2: target/release/jaq -n "[range(0; 1000000)] | group_by(. % 2) | empty"
  Time (mean ± σ):     511.5 ms ±   1.5 ms    [User: 427.2 ms, System: 84.1 ms]
  Range (min … max):   509.0 ms … 514.1 ms    10 runs
 
Benchmark 3: ./jq-linux-amd64-1.7 -n "[range(0; 1000000)] | group_by(. % 2) | empty"
  Time (mean ± σ):      1.952 s ±  0.006 s    [User: 1.855 s, System: 0.097 s]
  Range (min … max):    1.945 s …  1.963 s    10 runs
 
Summary
  './jaq-before -n "[range(0; 1000000)] | group_by(. % 2) | empty"' ran
    1.04 ± 0.01 times faster than 'target/release/jaq -n "[range(0; 1000000)] | group_by(. % 2) | empty"'
    3.97 ± 0.02 times faster than './jq-linux-amd64-1.7 -n "[range(0; 1000000)] | group_by(. % 2) | empty"'

But as we can see, it is still way faster than jq 1.7. So this is fine.

@01mf02 01mf02 merged commit bb4a0dd into main Jan 9, 2024
2 checks passed
@01mf02 01mf02 deleted the group-by-next branch January 9, 2024 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant