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

GH-26648: [C++] Optimize union equality comparison #45384

Merged
merged 6 commits into from
Feb 4, 2025

Conversation

mcshawn10
Copy link
Contributor

@mcshawn10 mcshawn10 commented Jan 29, 2025

Rationale for this change

#26648 proposes an optimization in checking sparse array equality by detecting contiguous runs, this PR implements that change

What changes are included in this PR?

previously, sparse array comparison was checked one by one, in this change, contiguous runs are detected and compared by checking equality of current and previous child_ids

Are these changes tested?

already covered by existing unit tests

Are there any user-facing changes?

no

Copy link

⚠️ GitHub issue #26648 has been automatically assigned in GitHub to PR creator.

@mapleFU
Copy link
Member

mapleFU commented Jan 31, 2025

Thanks! By the way is there any benchmark result for this pr?

@mcshawn10
Copy link
Contributor Author

Thanks! By the way is there any benchmark result for this pr?

still figuring that part out! 😅

@mcshawn10
Copy link
Contributor Author

mcshawn10 commented Jan 31, 2025

overall.json

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Non-regressions: (6)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                              benchmark          baseline          contender  change %                                                                                                                                                                                                   counters
    ArrayRangeEqualsSparseUnion/65536/0 47.119M items/sec 105.533M items/sec   123.973      {'family_index': 0, 'per_family_instance_index': 5, 'run_name': 'ArrayRangeEqualsSparseUnion/65536/0', 'repetitions': 1, 'repetition_index': 0, 'threads': 1, 'iterations': 506, 'null_percent': 0.0}
  ArrayRangeEqualsSparseUnion/65536/100 29.924M items/sec  57.186M items/sec    91.101    {'family_index': 0, 'per_family_instance_index': 1, 'run_name': 'ArrayRangeEqualsSparseUnion/65536/100', 'repetitions': 1, 'repetition_index': 0, 'threads': 1, 'iterations': 326, 'null_percent': 1.0}
ArrayRangeEqualsSparseUnion/65536/10000 30.820M items/sec  57.887M items/sec    87.826 {'family_index': 0, 'per_family_instance_index': 0, 'run_name': 'ArrayRangeEqualsSparseUnion/65536/10000', 'repetitions': 1, 'repetition_index': 0, 'threads': 1, 'iterations': 325, 'null_percent': 0.01}
   ArrayRangeEqualsSparseUnion/65536/10 30.616M items/sec  56.025M items/sec    82.990    {'family_index': 0, 'per_family_instance_index': 2, 'run_name': 'ArrayRangeEqualsSparseUnion/65536/10', 'repetitions': 1, 'repetition_index': 0, 'threads': 1, 'iterations': 331, 'null_percent': 10.0}
    ArrayRangeEqualsSparseUnion/65536/1 46.987M items/sec  82.663M items/sec    75.926    {'family_index': 0, 'per_family_instance_index': 4, 'run_name': 'ArrayRangeEqualsSparseUnion/65536/1', 'repetitions': 1, 'repetition_index': 0, 'threads': 1, 'iterations': 488, 'null_percent': 100.0}
    ArrayRangeEqualsSparseUnion/65536/2 31.326M items/sec  54.119M items/sec    72.760     {'family_index': 0, 'per_family_instance_index': 3, 'run_name': 'ArrayRangeEqualsSparseUnion/65536/2', 'repetitions': 1, 'repetition_index': 0, 'threads': 1, 'iterations': 340, 'null_percent': 50.0}

@pitrou pitrou changed the title GH-26648: [C++] Optimize union equality comparison #26648 GH-26648: [C++] Optimize union equality comparison Feb 4, 2025
Copy link
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your PR @mcshawn10 . This looks mostly good, here are two minor suggestions.

}
}

// Handle the final run
const auto final_child_num = child_ids[left_codes[left_start_idx_ + run_start]];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably only do this final comparison if result_ is still true.


if (!impl.Compare()) {
result_ = false;
return Status::OK();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can break just as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for the feedback! just implemented the suggestions

@github-actions github-actions bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Feb 4, 2025
@pitrou
Copy link
Member

pitrou commented Feb 4, 2025

It turns out that we didn't have any proper tests for sparse union comparison, so I added one.

@pitrou pitrou merged commit 1567be0 into apache:main Feb 4, 2025
37 checks passed
@pitrou pitrou removed the awaiting committer review Awaiting committer review label Feb 4, 2025
Copy link

After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit 1567be0.

There were 8 benchmark results with an error:

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 1 possible false positive for unstable benchmarks that are known to sometimes produce them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants