-
Couldn't load subscription status.
- Fork 537
chore(performance): optimize JSON parsing in get_actions and snapshot reading #3830
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d50077b
chore(performance): optimize JSON parsing in get_actions and snapshot…
fvaleye 9227d00
Merge branch 'main' into performance/json-parsing
fvaleye 58f8f6d
Merge branch 'main' into performance/json-parsing
rtyler 04f45e2
Merge branch 'main' into performance/json-parsing
fvaleye File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| use bytes::Bytes; | ||
| use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput}; | ||
| use std::io::{BufRead, BufReader, Cursor}; | ||
| use std::time::Duration; | ||
| use tokio::runtime::Runtime; | ||
|
|
||
| use deltalake_core::kernel::Action; | ||
| use deltalake_core::logstore::get_actions; | ||
| use deltalake_core::DeltaTableError; | ||
|
|
||
| fn generate_commit_log_complex( | ||
| num_actions: usize, | ||
| with_stats: bool, | ||
| with_partition_values: bool, | ||
| with_deletion_vector: bool, | ||
| ) -> Bytes { | ||
| let mut log_lines = Vec::new(); | ||
|
|
||
| log_lines.push(r#"{"protocol":{"minReaderVersion":1,"minWriterVersion":2}}"#.to_string()); | ||
| log_lines.push(r#"{"commitInfo":{"timestamp":1234567890}}"#.to_string()); | ||
|
|
||
| for i in 0..num_actions { | ||
| let mut add_json = format!( | ||
| r#"{{"path":"part-{:05}.parquet","size":{},"modificationTime":1234567890,"dataChange":true"#, | ||
| i, | ||
| 1000 + i * 100 | ||
| ); | ||
|
|
||
| if with_partition_values { | ||
| add_json.push_str(r#","partitionValues":{"year":"2024","month":"10","day":"09"}"#); | ||
| } else { | ||
| add_json.push_str(r#","partitionValues":{}"#); | ||
| } | ||
|
|
||
| if with_stats { | ||
| add_json.push_str(&format!( | ||
| r#","stats":"{{\"numRecords\":{},\"minValues\":{{\"id\":{},\"name\":\"aaa\",\"value\":{}.5}},\"maxValues\":{{\"id\":{},\"name\":\"zzz\",\"value\":{}.99}},\"nullCount\":{{\"id\":0,\"name\":0,\"value\":{}}}}}""#, | ||
| 1000 + i * 10, i, i, i + 1000, i + 1000, i % 10 | ||
| )); | ||
| } | ||
|
|
||
| if with_deletion_vector { | ||
| add_json.push_str(r#","deletionVector":{"storageType":"u","pathOrInlineDv":"vBn[lx{q8@P<9BNH/isA","offset":1,"sizeInBytes":36,"cardinality":2}"#); | ||
| } | ||
|
|
||
| add_json.push_str("}"); | ||
| log_lines.push(format!(r#"{{"add":{}}}"#, add_json)); | ||
| } | ||
|
|
||
| Bytes::from(log_lines.join("\n")) | ||
| } | ||
|
|
||
| // Baseline implementation for comparison | ||
| // TODO: this is the version of the main branch for performance comparison | ||
| // Remove it after merging the PR | ||
| async fn get_actions_baseline( | ||
| version: i64, | ||
| commit_log_bytes: Bytes, | ||
| ) -> Result<Vec<Action>, DeltaTableError> { | ||
| let reader = BufReader::new(Cursor::new(commit_log_bytes)); | ||
|
|
||
| let mut actions = Vec::new(); | ||
| for re_line in reader.lines() { | ||
| let line = re_line?; | ||
| let lstr = line.as_str(); | ||
| let action = serde_json::from_str(lstr).map_err(|e| DeltaTableError::InvalidJsonLog { | ||
| json_err: e, | ||
| line, | ||
| version, | ||
| })?; | ||
| actions.push(action); | ||
| } | ||
| Ok(actions) | ||
| } | ||
|
|
||
| fn bench_simple_actions(c: &mut Criterion) { | ||
| let rt = Runtime::new().unwrap(); | ||
| let mut group = c.benchmark_group("simple_actions_1000"); | ||
| group.throughput(Throughput::Elements(1000)); | ||
| group.sample_size(150); | ||
| group.measurement_time(Duration::from_secs(10)); | ||
|
|
||
| let commit_log = generate_commit_log_complex(1000, false, false, false); | ||
|
|
||
| group.bench_function("baseline", |b| { | ||
| b.iter(|| { | ||
| rt.block_on(async { | ||
| let result = get_actions_baseline(0, commit_log.clone()).await; | ||
| black_box(result.unwrap().len()) | ||
| }) | ||
| }); | ||
| }); | ||
|
|
||
| group.bench_function("new version", |b| { | ||
| b.iter(|| { | ||
| rt.block_on(async { | ||
| let result = get_actions(0, &commit_log).await; | ||
| black_box(result.unwrap().len()) | ||
| }) | ||
| }); | ||
| }); | ||
|
|
||
| group.finish(); | ||
| } | ||
|
|
||
| fn bench_with_stats(c: &mut Criterion) { | ||
| let rt = Runtime::new().unwrap(); | ||
| let mut group = c.benchmark_group("with_stats_1000"); | ||
| group.throughput(Throughput::Elements(1000)); | ||
| group.sample_size(150); | ||
| group.measurement_time(Duration::from_secs(10)); | ||
|
|
||
| let commit_log = generate_commit_log_complex(1000, true, false, false); | ||
|
|
||
| group.bench_function("baseline", |b| { | ||
| b.iter(|| { | ||
| rt.block_on(async { | ||
| let result = get_actions_baseline(0, commit_log.clone()).await; | ||
| black_box(result.unwrap().len()) | ||
| }) | ||
| }); | ||
| }); | ||
|
|
||
| group.bench_function("new version", |b| { | ||
| b.iter(|| { | ||
| rt.block_on(async { | ||
| let result = get_actions(0, &commit_log).await; | ||
| black_box(result.unwrap().len()) | ||
| }) | ||
| }); | ||
| }); | ||
|
|
||
| group.finish(); | ||
| } | ||
|
|
||
| fn bench_full_complexity(c: &mut Criterion) { | ||
| let rt = Runtime::new().unwrap(); | ||
| let mut group = c.benchmark_group("full_complexity_1000"); | ||
| group.throughput(Throughput::Elements(1000)); | ||
| group.sample_size(150); | ||
| group.measurement_time(Duration::from_secs(10)); | ||
|
|
||
| let commit_log = generate_commit_log_complex(1000, true, true, true); | ||
|
|
||
| group.bench_function("baseline", |b| { | ||
| b.iter(|| { | ||
| rt.block_on(async { | ||
| let result = get_actions_baseline(0, commit_log.clone()).await; | ||
| black_box(result.unwrap().len()) | ||
| }) | ||
| }); | ||
| }); | ||
|
|
||
| group.bench_function("new version", |b| { | ||
| b.iter(|| { | ||
| rt.block_on(async { | ||
| let result = get_actions(0, &commit_log).await; | ||
| black_box(result.unwrap().len()) | ||
| }) | ||
| }); | ||
| }); | ||
|
|
||
| group.finish(); | ||
| } | ||
|
|
||
| criterion_group!( | ||
| benches, | ||
| bench_simple_actions, | ||
| bench_with_stats, | ||
| bench_full_complexity, | ||
| ); | ||
| criterion_main!(benches); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why this function is async. There's nothing async inside of it. Not your fault as the base function was also async, but probably some legacy tech debt? I can imagine there was a world where this function took an async bytes stream instead of all the bytes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
per git blame, this function was implemented two years ago as async even though there were no async in it at any time.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I kept the function
async.Removing
asyncwould be a minor breaking change, as it would also require removing.awaitfrom the callers.Let's see what @roeap and @rtyler think about this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more generally speaking, I see most call sites disappearing short term, since log replay nor produces record batches that we extract data from (i.e.
LogFileViewet. al.) avoiding copies whenver possible.Exception being calling this in
commit_infos.Sine we are passing in
Bytes, I see no reason why we should be doing IO in this function, and with that also little reason for it to be async ... maybe in a follow-up we can make it sync.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, let's see when we have fully kernelized conflict resolution. There might be a few surprises lurking 😆.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay!
Let's keep it like this for now and make it sync later.
I will create an issue for tracking this need.