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

[C++] Document the guarantees of ChunkResolver::Resolve and minimize branching #39815

Closed
felipecrv opened this issue Jan 27, 2024 · 0 comments · Fixed by #39817
Closed

[C++] Document the guarantees of ChunkResolver::Resolve and minimize branching #39815

felipecrv opened this issue Jan 27, 2024 · 0 comments · Fixed by #39817

Comments

@felipecrv
Copy link
Contributor

Describe the enhancement requested

The invariants of ChunkResolver and pre-conditions of ChunkResolver::Resolve() are unclear which can lead to multiple problems:

  1. Misuse
  2. Misunderstanding that leads to addition of more checks that can kill speculative execution in tight loops
  3. Missed micro-optmization opportunities

Request: document the class and implement possible micro-optmizations.

Component(s)

C++

@felipecrv felipecrv self-assigned this Jan 27, 2024
felipecrv added a commit that referenced this issue Jan 29, 2024
…39817)

### Rationale for this change

There has been interest in improving operations on chunked-arrays and even though `ChunkResolver::Resolve()` is not a big contributor in most kernels, the fact that it can be used from tight loops warrants careful attention to branch prediction and memory effects of its implementation.

### What changes are included in this PR?

 - Documentation of invariants and behavior of functions
 - Multiple optimizations justified by microbenchmarks
 - Addition of a variation of `Resolve` that takes a hint as parameter
 - Fix of an out-of-bounds memory access that doesn't affect correctness (it can only reduce effectiveness of cache in very rare situations, but is nevertheless an issue)

### Are these changes tested?

Yes, by existing tests.

### Are there any user-facing changes?

 - The `arrow::internal::ChunkResolver::Bisect()` function was `protected` and is now `private` with a different signature
* Closes: #39815

Authored-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
Signed-off-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
@felipecrv felipecrv added this to the 16.0.0 milestone Jan 29, 2024
dgreiss pushed a commit to dgreiss/arrow that referenced this issue Feb 19, 2024
…lve() (apache#39817)

### Rationale for this change

There has been interest in improving operations on chunked-arrays and even though `ChunkResolver::Resolve()` is not a big contributor in most kernels, the fact that it can be used from tight loops warrants careful attention to branch prediction and memory effects of its implementation.

### What changes are included in this PR?

 - Documentation of invariants and behavior of functions
 - Multiple optimizations justified by microbenchmarks
 - Addition of a variation of `Resolve` that takes a hint as parameter
 - Fix of an out-of-bounds memory access that doesn't affect correctness (it can only reduce effectiveness of cache in very rare situations, but is nevertheless an issue)

### Are these changes tested?

Yes, by existing tests.

### Are there any user-facing changes?

 - The `arrow::internal::ChunkResolver::Bisect()` function was `protected` and is now `private` with a different signature
* Closes: apache#39815

Authored-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
Signed-off-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
zanmato1984 pushed a commit to zanmato1984/arrow that referenced this issue Feb 28, 2024
…lve() (apache#39817)

### Rationale for this change

There has been interest in improving operations on chunked-arrays and even though `ChunkResolver::Resolve()` is not a big contributor in most kernels, the fact that it can be used from tight loops warrants careful attention to branch prediction and memory effects of its implementation.

### What changes are included in this PR?

 - Documentation of invariants and behavior of functions
 - Multiple optimizations justified by microbenchmarks
 - Addition of a variation of `Resolve` that takes a hint as parameter
 - Fix of an out-of-bounds memory access that doesn't affect correctness (it can only reduce effectiveness of cache in very rare situations, but is nevertheless an issue)

### Are these changes tested?

Yes, by existing tests.

### Are there any user-facing changes?

 - The `arrow::internal::ChunkResolver::Bisect()` function was `protected` and is now `private` with a different signature
* Closes: apache#39815

Authored-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
Signed-off-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
thisisnic pushed a commit to thisisnic/arrow that referenced this issue Mar 8, 2024
…lve() (apache#39817)

### Rationale for this change

There has been interest in improving operations on chunked-arrays and even though `ChunkResolver::Resolve()` is not a big contributor in most kernels, the fact that it can be used from tight loops warrants careful attention to branch prediction and memory effects of its implementation.

### What changes are included in this PR?

 - Documentation of invariants and behavior of functions
 - Multiple optimizations justified by microbenchmarks
 - Addition of a variation of `Resolve` that takes a hint as parameter
 - Fix of an out-of-bounds memory access that doesn't affect correctness (it can only reduce effectiveness of cache in very rare situations, but is nevertheless an issue)

### Are these changes tested?

Yes, by existing tests.

### Are there any user-facing changes?

 - The `arrow::internal::ChunkResolver::Bisect()` function was `protected` and is now `private` with a different signature
* Closes: apache#39815

Authored-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
Signed-off-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant