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

Specialize interleave string ~2-3x faster #2944

Merged
merged 3 commits into from Oct 27, 2022

Conversation

tustvold
Copy link
Contributor

Which issue does this PR close?

Part of #2864

Rationale for this change

interleave str(20, 0.0) 100 [0..100, 100..230, 450..1000]
                        time:   [1.0792 µs 1.0795 µs 1.0799 µs]
                        change: [-60.193% -60.122% -60.019%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
  3 (3.00%) high mild
  3 (3.00%) high severe

interleave str(20, 0.0) 400 [0..100, 100..230, 450..1000]
                        time:   [3.2179 µs 3.2187 µs 3.2197 µs]
                        change: [-60.739% -60.622% -60.497%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 11 outliers among 100 measurements (11.00%)
  4 (4.00%) low mild
  2 (2.00%) high mild
  5 (5.00%) high severe

interleave str(20, 0.0) 1024 [0..100, 100..230, 450..1000]
                        time:   [7.4057 µs 7.4079 µs 7.4101 µs]
                        change: [-60.606% -60.542% -60.442%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 3 outliers among 100 measurements (3.00%)
  2 (2.00%) high mild
  1 (1.00%) high severe

interleave str(20, 0.0) 1024 [0..100, 100..230, 450..1000, 0..1000]
                        time:   [7.4336 µs 7.4369 µs 7.4403 µs]
                        change: [-58.701% -58.630% -58.525%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 9 outliers among 100 measurements (9.00%)
  7 (7.00%) high mild
  2 (2.00%) high severe

interleave str(20, 0.5) 100 [0..100, 100..230, 450..1000]
                        time:   [1.6810 µs 1.6815 µs 1.6821 µs]
                        change: [-58.572% -58.434% -58.308%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 7 outliers among 100 measurements (7.00%)
  1 (1.00%) low mild
  4 (4.00%) high mild
  2 (2.00%) high severe

interleave str(20, 0.5) 400 [0..100, 100..230, 450..1000]
                        time:   [5.2158 µs 5.2246 µs 5.2341 µs]
                        change: [-64.090% -63.972% -63.864%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high severe

interleave str(20, 0.5) 1024 [0..100, 100..230, 450..1000]
                        time:   [16.993 µs 17.013 µs 17.032 µs]
                        change: [-54.202% -54.077% -53.991%] (p = 0.00 < 0.05)
                        Performance has improved.

interleave str(20, 0.5) 1024 [0..100, 100..230, 450..1000, 0..1000]
                        time:   [17.424 µs 17.443 µs 17.464 µs]
                        change: [-52.353% -52.256% -52.128%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 4 outliers among 100 measurements (4.00%)
  3 (3.00%) high mild
  1 (1.00%) high severe

What changes are included in this PR?

Adds a specialized implementation for string arrays

Are there any user-facing changes?

No

@github-actions github-actions bot added the arrow Changes to the arrow crate label Oct 26, 2022
@tustvold
Copy link
Contributor Author

With #2947 this will be generalizable to also cover byte arrays

tustvold added a commit to tustvold/arrow-rs that referenced this pull request Oct 27, 2022
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

LGTM -- thank you

(*end - *start).to_usize().unwrap(),
);
let slice =
std::slice::from_raw_parts(self.value_data.as_ptr().add(start), end - start);
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a drive by cleanup right?

_ => interleave_fallback(values, indices)
}
}

/// Common functionality for interleaving arrays
struct Interleave<'a, T> {
Copy link
Contributor

Choose a reason for hiding this comment

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

some comments might help here specifically what null_count and nulls represent and what the generic T is used for

as_primitive_array::<T>(*x)
})
.collect();
let interleaved = Interleave::<'_, PrimitiveArray<T>>::new(values, indices);
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

offsets.append(O::from_usize(0).unwrap());
for (a, b) in indices {
let o = interleaved.arrays[*a].value_offsets();
let len = o[*b + 1].as_usize() - o[*b].as_usize();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let len = o[*b + 1].as_usize() - o[*b].as_usize();
// element length
let len = o[*b + 1].as_usize() - o[*b].as_usize();

let mut capacity = 0;
let mut offsets = BufferBuilder::<O>::new(indices.len() + 1);
offsets.append(O::from_usize(0).unwrap());
for (a, b) in indices {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is clever -- do the offsets in one pass and the strings in another

@tustvold tustvold merged commit 66ea66b into apache:master Oct 27, 2022
@ursabot
Copy link

ursabot commented Oct 27, 2022

Benchmark runs are scheduled for baseline = d625f0a and contender = 66ea66b. 66ea66b is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

tustvold added a commit to tustvold/arrow-rs that referenced this pull request Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants