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

refactor: Add some comments #16008

Merged
merged 1 commit into from
May 2, 2024
Merged

refactor: Add some comments #16008

merged 1 commit into from
May 2, 2024

Conversation

ritchie46
Copy link
Member

No description provided.

@github-actions github-actions bot added internal An internal refactor or improvement python Related to Python Polars rust Related to Rust Polars labels May 2, 2024
Copy link
Member Author

@ritchie46 ritchie46 left a comment

Choose a reason for hiding this comment

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

@@ -54,6 +55,8 @@ pub(crate) fn get_offsets(
}
}

/// Reads bytes from `file` to `buf` and returns pointers into `buf` that can be parsed.
/// TODO! this can be implemented without copying by pointing in the memmapped file.
Copy link
Member Author

Choose a reason for hiding this comment

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

Currently this reads from file into buf and then returns offsets (SyncPtr<u8>, usize), which is semantically (*const u8, usize), being the starting offset ptr and the length of the chunk that can be parsed.

These pointers currently point into buf. However we can directly mmap the file and point into the memory mapped slice directly. This saves an explicit read and reslice (copy remaningin bytes to start of buf).

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was looking through and noticed that we also have an mmap-based reader at:

pub struct BatchedCsvReaderMmap<'a> {

It looks like we switch between the 2 readers depending on low_memory:

let batched_reader = if options.low_memory {
let batched_reader = unsafe { Box::new((*reader).batched_borrowed_read()?) };
let batched_reader = Box::leak(batched_reader) as *mut BatchedCsvReaderRead;
Either::Right(batched_reader)
} else {
let batched_reader = unsafe { Box::new((*reader).batched_borrowed_mmap()?) };
let batched_reader = Box::leak(batched_reader) as *mut BatchedCsvReaderMmap;
Either::Left(batched_reader)
};

I'm thinking we can maybe just always use the mmap reader? I don't think mmap should be memory intensive, and we could also adjust how far we seek as well to accomodate low memory conditions.

@@ -109,18 +112,23 @@ impl<'a> ChunkReader<'a> {
self.buf_end = 0;
}

fn return_slice(&self, start: usize, end: usize) -> (usize, usize) {
fn return_slice(&self, start: usize, end: usize) -> (SyncPtr<u8>, usize) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Return SyncPtr as it is more clear that we return pointers that way.

///
/// This will make a pointer sync and send.
/// Ensure that you don't break aliasing rules.
pub unsafe fn from_const(ptr: *const T) -> Self {
Copy link
Member Author

Choose a reason for hiding this comment

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

Creating this isn't unsafe.

Copy link

codecov bot commented May 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.91%. Comparing base (8929395) to head (bc8cdd9).
Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16008      +/-   ##
==========================================
- Coverage   80.95%   80.91%   -0.05%     
==========================================
  Files        1384     1384              
  Lines      178151   178181      +30     
  Branches     3043     3050       +7     
==========================================
- Hits       144229   144179      -50     
- Misses      33439    33513      +74     
- Partials      483      489       +6     
Flag Coverage Δ
python 74.41% <100.00%> (-0.05%) ⬇️
rust 78.13% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@ritchie46 ritchie46 merged commit e259d7f into main May 2, 2024
21 checks passed
@ritchie46 ritchie46 deleted the comments branch May 2, 2024 08:00
AlexanderNenninger pushed a commit to AlexanderNenninger/polars that referenced this pull request May 3, 2024
@c-peters c-peters added the accepted Ready for implementation label May 6, 2024
Wouittone pushed a commit to Wouittone/polars that referenced this pull request Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation internal An internal refactor or improvement 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