Skip to content

perf: stable row id prefilter - #2706

Merged
wjones127 merged 5 commits into
lance-format:mainfrom
wjones127:stable-row-id-perf
Aug 22, 2024
Merged

wjones127 merged 5 commits into
lance-format:mainfrom
wjones127:stable-row-id-perf

Conversation

@wjones127

Copy link
Copy Markdown
Contributor

Cache the row id mask prefilter and make it faster to construct.

@codecov-commenter

codecov-commenter commented Aug 7, 2024 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 91.23711% with 17 lines in your changes missing coverage. Please review.

Project coverage is 79.25%. Comparing base (a9c678d) to head (a144695).
Report is 2 commits behind head on main.

Files Patch % Lines
rust/lance-core/src/utils/mask.rs 0.00% 7 Missing ⚠️
rust/lance/src/index/prefilter.rs 88.23% 0 Missing and 4 partials ⚠️
rust/lance-core/src/utils/deletion.rs 83.33% 2 Missing ⚠️
rust/lance/src/dataset/optimize.rs 77.77% 1 Missing and 1 partial ⚠️
rust/lance-table/src/rowids.rs 98.78% 0 Missing and 1 partial ⚠️
rust/lance-table/src/rowids/segment.rs 98.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2706      +/-   ##
==========================================
+ Coverage   79.21%   79.25%   +0.04%     
==========================================
  Files         227      227              
  Lines       67733    67947     +214     
  Branches    67733    67947     +214     
==========================================
+ Hits        53652    53851     +199     
- Misses      10968    10978      +10     
- Partials     3113     3118       +5     
Flag Coverage Δ
unittests 79.25% <91.23%> (+0.04%) ⬆️

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.

@wjones127 wjones127 mentioned this pull request Aug 12, 2024
8 of 13 tasks
@wjones127
wjones127 marked this pull request as ready for review August 15, 2024 16:24

@westonpace westonpace left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, nice work on the mask function.

Comment on lines +765 to +821
#[test]
fn test_row_id_mask() {
// 0, 1, 2, 3, 4
// 50, 51, 52, 55, 56, 57, 58, 59
// 7, 9
// 10, 12, 14
// 35, 39
let sequence = RowIdSequence(vec![
U64Segment::Range(0..5),
U64Segment::RangeWithHoles {
range: 50..60,
holes: vec![53, 54].into(),
},
U64Segment::SortedArray(vec![7, 9].into()),
U64Segment::RangeWithBitmap {
range: 10..15,
bitmap: [true, false, true, false, true].as_slice().into(),
},
U64Segment::Array(vec![35, 39].into()),
]);

// Masking one in each segment
let values_to_remove = [4, 55, 7, 12, 39];
let positions_to_remove = sequence
.iter()
.enumerate()
.filter_map(|(i, val)| {
if values_to_remove.contains(&val) {
Some(i as u32)
} else {
None
}
})
.collect::<Vec<_>>();
let mut sequence = sequence;
sequence.mask(positions_to_remove).unwrap();
let expected = RowIdSequence(vec![
U64Segment::Range(0..4),
U64Segment::RangeWithBitmap {
range: 50..60,
bitmap: [
true, true, true, false, false, false, true, true, true, true,
]
.as_slice()
.into(),
},
U64Segment::Range(9..10),
U64Segment::RangeWithBitmap {
range: 10..15,
bitmap: [true, false, false, false, true].as_slice().into(),
},
U64Segment::Array(vec![35].into()),
]);
assert_eq!(sequence, expected);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What happens if you mask out every row id in a segment?

Comment thread rust/lance-table/src/rowids/segment.rs Outdated
Comment on lines +415 to +417
.filter(|(sequential_i, i)| **i != *sequential_i as u32)
.map(|(sequential_i, _)| sequential_i)
.next()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you use find or find_map?

Comment thread rust/lance-table/src/rowids/segment.rs Outdated
sorted,
};

let make_new_iter = || {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is a named closure needed here? Can't you just execute it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I could, but that just wouldn't be convoluted enough. 😄

I'll simplify this.

Comment thread rust/lance/src/index/prefilter.rs Outdated
let (row_ids, deletion_vector) = join!(row_ids, deletion_vector);
Ok::<_, crate::Error>((row_ids?, deletion_vector?))
})
.buffer_unordered(10)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see you just moved this function but maybe let's get rid of the random 10?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What is our best practice right now. I don't love this, but I just don't know what our current preferred pattern is right now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since it's mostly I/O driven I'd recommend dataset.object_store().io_parallelism()?

Comment thread rust/lance/src/index/prefilter.rs Outdated

// The process of computing the final mask is CPU-bound, so we spawn it
// on a blocking thread.
let allow_list = tokio::task::spawn_blocking(move || {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Perhaps we should use spawn_cpu here?

@wjones127
wjones127 merged commit eb87bfa into lance-format:main Aug 22, 2024
@wjones127
wjones127 deleted the stable-row-id-perf branch August 22, 2024 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants