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: Reduce copy in MemSlice #17983

Merged
merged 3 commits into from
Aug 1, 2024
Merged

Conversation

nameexhaustion
Copy link
Collaborator

No description provided.

@github-actions github-actions bot added performance Performance issues or improvements python Related to Python Polars rust Related to Rust Polars labels Aug 1, 2024
#[cfg(all(feature = "async", feature = "parquet"))]
ColumnStore::Fetched(fetched) => {
let entry = fetched.get(&start).unwrap_or_else(|| {
panic!(
"mmap_columns: column with start {start} must be prefetched in ColumnStore.\n"
)
});
MemSlice::from_slice(entry.as_ref())
MemSlice::from_bytes(entry.clone())
Copy link
Collaborator Author

@nameexhaustion nameexhaustion Aug 1, 2024

Choose a reason for hiding this comment

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

We now support zero-copy from bytes::Bytes

Copy link
Member

Choose a reason for hiding this comment

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

Nice!


/// Construct a `MemSlice` that simply wraps around a `&[u8]`.
#[inline]
pub fn from_slice(slice: &'static [u8]) -> Self {
Copy link
Collaborator Author

@nameexhaustion nameexhaustion Aug 1, 2024

Choose a reason for hiding this comment

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

Changes from_slice - previously it copied into a new Arc<[u8]>, but now it simply wraps the slice.

For context, this is only used by ReaderBytes<'a>. I think one day we can refactor/replace ReaderBytes - the way we currently use that 'a lifetime is not ideal

// `slice` is not 'static - it is backed by `inner`. This is safe as long as `slice` is not
// directly accessed, and we are in a private module to guarantee that. Access should only
// be done through `Deref<Target = [u8]>`, which automatically gives the correct lifetime.
slice: &'static [u8],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Deref without matching on the enum

Copy link

codecov bot commented Aug 1, 2024

Codecov Report

Attention: Patch coverage is 81.81818% with 20 lines in your changes missing coverage. Please review.

Project coverage is 80.42%. Comparing base (6065465) to head (9062c9c).
Report is 1 commits behind head on main.

Files Patch % Lines
crates/polars-utils/src/mmap.rs 80.19% 20 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17983      +/-   ##
==========================================
+ Coverage   80.39%   80.42%   +0.03%     
==========================================
  Files        1494     1494              
  Lines      196480   196488       +8     
  Branches     2817     2817              
==========================================
+ Hits       157957   158027      +70     
+ Misses      38003    37941      -62     
  Partials      520      520              

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

@nameexhaustion nameexhaustion marked this pull request as ready for review August 1, 2024 08:22
@ritchie46 ritchie46 merged commit b5afc8f into pola-rs:main Aug 1, 2024
21 checks passed
@coastalwhite
Copy link
Collaborator

LFTM 😄

@nameexhaustion nameexhaustion deleted the mem-slice branch August 4, 2024 10:31
@c-peters c-peters added the accepted Ready for implementation label Aug 5, 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.

4 participants