Large files on an aindrive drive open several times faster
Agents / bot (pull_request) Successful in 7m0s
Agents / bot (pull_request) Successful in 7m0s
The host reads a file one 1 MiB slice per call, and every slice fetched the whole file again, so an 8 MiB file crossed the network eight times. The last file read is now kept for the slices that follow: each slice still stats the file first and reuses the reply only at the same revision, so a file changed in between is fetched afresh. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -524,3 +524,39 @@ async fn only_a_server_error_leaves_a_save_unknown() -> Result<(), ErrorCode> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn slices_of_one_revision_fetch_the_file_once() -> Result<(), ErrorCode> {
|
||||
let bytes: Vec<u8> = (0..=255).cycle().take(30_000).collect();
|
||||
let mut drive = sample();
|
||||
drive
|
||||
.files
|
||||
.insert("data.bin".to_owned(), test_host::file(&bytes, "5"));
|
||||
let drive = test_host::install(drive);
|
||||
Aindrive::open("aindrive".to_owned(), config())?;
|
||||
let mut read = Vec::new();
|
||||
while read.len() < bytes.len() {
|
||||
let reader = download(&at("/data.bin"), read.len() as u64)?;
|
||||
read.extend(reader.pull(7_000)?);
|
||||
}
|
||||
assert_eq!(read, bytes);
|
||||
let count = |tool: &str| {
|
||||
drive
|
||||
.borrow()
|
||||
.seen
|
||||
.iter()
|
||||
.filter(|seen| seen.tool.as_deref() == Some(tool))
|
||||
.count()
|
||||
};
|
||||
assert_eq!(count("read_file"), 1);
|
||||
assert!(count("stat") >= 5);
|
||||
|
||||
// Another revision is another file, fetched afresh.
|
||||
drive
|
||||
.borrow_mut()
|
||||
.files
|
||||
.insert("data.bin".to_owned(), test_host::file(b"replaced", "6"));
|
||||
assert_eq!(read_from("/data.bin", 0, 100)?.0, b"replaced");
|
||||
assert_eq!(count("read_file"), 2);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user