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: Batch nested Parquet decoding #17542

Merged
merged 1 commit into from
Jul 10, 2024

Conversation

coastalwhite
Copy link
Collaborator

@coastalwhite coastalwhite commented Jul 10, 2024

This PR is a follow up to #17462. This batches the collects in the nested Parquet decoders, with that we can also simplify the code quite a lot.

I did a benchmark where we had one column { 'x': pl.List(pl.Int8) } of length 10_000_000. Then, we read that Parquet file 50 times. Here are the results.

Benchmark 1: After Optimization
  Time (mean ± σ):      3.398 s ±  0.064 s    [User: 49.412 s, System: 4.362 s]
  Range (min … max):    3.311 s …  3.490 s    10 runs

Benchmark 2: Before Optimization
  Time (mean ± σ):      4.135 s ±  0.015 s    [User: 59.506 s, System: 5.234 s]
  Range (min … max):    4.105 s …  4.149 s    10 runs

Summary
  After Optimization ran
    1.22 ± 0.02 times faster than Before Optimization

The nested decoder is still relatively inefficient, but this is a step in the right direction.

This PR is a follow up to pola-rs#17462. This batches the collects in the nested
Parquet decoders, with that we can also simplify the code quite a lot.

I did a benchmark where we had one column `{ 'x': pl.List(pl.Int8) }` of length
`10_000_000`. Then, we read that Parquet file 50 times. Here are the results.

```
Benchmark 1: After Optimization
  Time (mean ± σ):      3.398 s ±  0.064 s    [User: 49.412 s, System: 4.362 s]
  Range (min … max):    3.311 s …  3.490 s    10 runs

Benchmark 2: Before Optimization
  Time (mean ± σ):      4.135 s ±  0.015 s    [User: 59.506 s, System: 5.234 s]
  Range (min … max):    4.105 s …  4.149 s    10 runs

Summary
  After Optimization ran
    1.22 ± 0.02 times faster than Before Optimization
```
@github-actions github-actions bot added performance Performance issues or improvements python Related to Python Polars rust Related to Rust Polars labels Jul 10, 2024
Copy link

codecov bot commented Jul 10, 2024

Codecov Report

Attention: Patch coverage is 55.99022% with 180 lines in your changes missing coverage. Please review.

Project coverage is 80.49%. Comparing base (a5724d6) to head (6e096aa).
Report is 3 commits behind head on main.

Files Patch % Lines
...arquet/src/arrow/read/deserialize/binary/nested.rs 0.00% 44 Missing ⚠️
...arrow/read/deserialize/fixed_size_binary/nested.rs 0.00% 42 Missing ⚠️
crates/polars-arrow/src/bitmap/utils/iterator.rs 63.33% 22 Missing ⚠️
...quet/src/parquet/encoding/hybrid_rle/translator.rs 13.04% 20 Missing ⚠️
...rquet/src/arrow/read/deserialize/binview/nested.rs 60.86% 18 Missing ⚠️
...arquet/src/arrow/read/deserialize/binview/basic.rs 18.18% 9 Missing ⚠️
...polars-parquet/src/arrow/read/deserialize/utils.rs 81.81% 6 Missing ⚠️
...parquet/src/arrow/read/deserialize/nested_utils.rs 83.33% 5 Missing ⚠️
...uet/src/arrow/read/deserialize/primitive/nested.rs 90.90% 4 Missing ⚠️
...quet/src/arrow/read/deserialize/binary/decoders.rs 40.00% 3 Missing ⚠️
... and 3 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17542      +/-   ##
==========================================
+ Coverage   80.47%   80.49%   +0.02%     
==========================================
  Files        1482     1483       +1     
  Lines      195119   195171      +52     
  Branches     2778     2778              
==========================================
+ Hits       157026   157109      +83     
+ Misses      37582    37551      -31     
  Partials      511      511              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ritchie46 ritchie46 merged commit a55d9bc into pola-rs:main Jul 10, 2024
23 checks passed
@coastalwhite coastalwhite deleted the parquet-batch-nested branch July 10, 2024 11:06
coastalwhite added a commit to coastalwhite/polars that referenced this pull request Jul 10, 2024
This continues on pola-rs#17542 and now also batches the actual Nesting, not only the top decoder.

I did the same benchmark with `POLARS_MAX_THREADS=1` and we again see a small
speedup. But I suspect that the speedup is larger for `FixedSizeList`s and
`Struct`s.

```
Benchmark 1: After Optimization
  Time (mean ± σ):     13.306 s ±  0.018 s    [User: 12.661 s, System: 0.614 s]
  Range (min … max):   13.263 s … 13.335 s    10 runs

Benchmark 2: Before Optimization
  Time (mean ± σ):     14.973 s ±  0.065 s    [User: 14.422 s, System: 0.517 s]
  Range (min … max):   14.887 s … 15.129 s    10 runs

Summary
  After Optimization ran
    1.13 ± 0.01 times faster than Before Optimization
```
coastalwhite added a commit to coastalwhite/polars that referenced this pull request Jul 10, 2024
This continues on pola-rs#17542 and now also batches the actual Nesting, not only the top decoder.

I did the same benchmark with `POLARS_MAX_THREADS=1` and we again see a small
speedup. But I suspect that the speedup is larger for `FixedSizeList`s and
`Struct`s.

```
Benchmark 1: After Optimization
  Time (mean ± σ):     13.306 s ±  0.018 s    [User: 12.661 s, System: 0.614 s]
  Range (min … max):   13.263 s … 13.335 s    10 runs

Benchmark 2: Before Optimization
  Time (mean ± σ):     14.973 s ±  0.065 s    [User: 14.422 s, System: 0.517 s]
  Range (min … max):   14.887 s … 15.129 s    10 runs

Summary
  After Optimization ran
    1.13 ± 0.01 times faster than Before Optimization
```
@c-peters c-peters added the accepted Ready for implementation label Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation performance Performance issues or improvements python Related to Python Polars rust Related to Rust Polars
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants