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

perf: inline from_iter for ScalarBuffer #7066

Merged
merged 1 commit into from
Feb 2, 2025

Conversation

0ax1
Copy link
Contributor

@0ax1 0ax1 commented Feb 2, 2025

When benchmarking ScalarBuffer::from_iter as part of https://github.com/spiraldb/vortex/blob/develop/vortex-buffer/benches/vortex_buffer.rs, the performance increases significantly if the function gets annotated with #[inline].

On a MacBook Air M2:

Without annotating from_iter with #[inline]:

vortex_buffer                                                 fastest       │ slowest       │ median        │ mean          │ samples │ iters
├─ from_iter                                                                │               │               │               │         │
│  ├─ Arrow<arrow_buffer::buffer::scalar::ScalarBuffer<i32>>                │               │               │               │         │
│  │  ├─ 1                                                    28.67 ns      │ 29.8 ns       │ 29.15 ns      │ 29.14 ns      │ 100     │ 25600
│  │  ├─ 100                                                  116.8 ns      │ 163.7 ns      │ 121.4 ns      │ 124.2 ns      │ 100     │ 3200
│  │  ├─ 1000                                                 614.3 ns      │ 895.5 ns      │ 632.5 ns      │ 670.1 ns      │ 100     │ 800
│  │  ├─ 100000                                               57.79 µs      │ 112.3 µs      │ 58.35 µs      │ 60.02 µs      │ 100     │ 100
│  │  ╰─ 10000000                                             7.425 ms      │ 9.524 ms      │ 7.844 ms      │ 8.113 ms      │ 100     │ 100
│  ╰─ Buffer<i32>                                                           │               │               │               │         │

After annotating from_iter with #[inline]:

vortex_buffer                                                 fastest       │ slowest       │ median        │ mean          │ samples │ iters
├─ from_iter                                                                │               │               │               │         │
│  ├─ Arrow<arrow_buffer::buffer::scalar::ScalarBuffer<i32>>                │               │               │               │         │
│  │  ├─ 1                                                    26.87 ns      │ 27.19 ns      │ 27.03 ns      │ 27.03 ns      │ 100     │ 25600
│  │  ├─ 100                                                  64.14 ns      │ 91.48 ns      │ 64.8 ns       │ 67.08 ns      │ 100     │ 6400
│  │  ├─ 1000                                                 79.77 ns      │ 115.5 ns      │ 81.08 ns      │ 88.88 ns      │ 100     │ 6400
│  │  ├─ 100000                                               5.165 µs      │ 53.83 µs      │ 5.541 µs      │ 6.642 µs      │ 100     │ 100
│  │  ╰─ 10000000                                             2.42 ms       │ 3.895 ms      │ 2.743 ms      │ 2.742 ms      │ 100     │ 100

When benchmarking `from_iter` as part of https://github.com/spiraldb/vortex/blob/develop/vortex-buffer/benches/vortex_buffer.rs,
the performance increases significantly if the function gets annotated with `#[inline]`.

On a MacBook Air M2:

Without annotating `from_iter` with `#[inline]`:

vortex_buffer                                                 fastest       │ slowest       │ median        │ mean          │ samples │ iters
├─ from_iter                                                                │               │               │               │         │
│  ├─ Arrow<arrow_buffer::buffer::scalar::ScalarBuffer<i32>>                │               │               │               │         │
│  │  ├─ 1                                                    28.67 ns      │ 29.8 ns       │ 29.15 ns      │ 29.14 ns      │ 100     │ 25600
│  │  ├─ 100                                                  116.8 ns      │ 163.7 ns      │ 121.4 ns      │ 124.2 ns      │ 100     │ 3200
│  │  ├─ 1000                                                 614.3 ns      │ 895.5 ns      │ 632.5 ns      │ 670.1 ns      │ 100     │ 800
│  │  ├─ 100000                                               57.79 µs      │ 112.3 µs      │ 58.35 µs      │ 60.02 µs      │ 100     │ 100
│  │  ╰─ 10000000                                             7.425 ms      │ 9.524 ms      │ 7.844 ms      │ 8.113 ms      │ 100     │ 100
│  ╰─ Buffer<i32>                                                           │               │               │               │         │

After annotating `from_iter` with `#[inline]`:

vortex_buffer                                                 fastest       │ slowest       │ median        │ mean          │ samples │ iters
├─ from_iter                                                                │               │               │               │         │
│  ├─ Arrow<arrow_buffer::buffer::scalar::ScalarBuffer<i32>>                │               │               │               │         │
│  │  ├─ 1                                                    26.87 ns      │ 27.19 ns      │ 27.03 ns      │ 27.03 ns      │ 100     │ 25600
│  │  ├─ 100                                                  64.14 ns      │ 91.48 ns      │ 64.8 ns       │ 67.08 ns      │ 100     │ 6400
│  │  ├─ 1000                                                 79.77 ns      │ 115.5 ns      │ 81.08 ns      │ 88.88 ns      │ 100     │ 6400
│  │  ├─ 100000                                               5.165 µs      │ 53.83 µs      │ 5.541 µs      │ 6.642 µs      │ 100     │ 100
│  │  ╰─ 10000000                                             2.42 ms       │ 3.895 ms      │ 2.743 ms      │ 2.742 ms      │ 100     │ 100
@github-actions github-actions bot added the arrow Changes to the arrow crate label Feb 2, 2025
Copy link
Contributor

@tustvold tustvold left a comment

Choose a reason for hiding this comment

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

Makes sense to me.

@0ax1
Copy link
Contributor Author

0ax1 commented Feb 2, 2025

Makes sense to me.

Thanks for having a look!

@tustvold tustvold merged commit c63b81d into apache:main Feb 2, 2025
26 checks passed
@0ax1 0ax1 deleted the perf-inline-from_iter branch February 2, 2025 19:52
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.

2 participants