Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix: reduce recording snapshot hashing overhead
Richie McIlroy6ae38bc9ce97
diff --git a/Cargo.lock b/Cargo.lockindex 12784ec9c..6f98ac0d9 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -199,7 +199,7 @@ checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0"dependencies = ["cfg-if","cipher",- "cpufeatures",+ "cpufeatures 0.2.17",][[package]]@@ -978,6 +978,19 @@ version = "2.6.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "6099cdc01846bc367c4e7dd630dc5966dccf36b652fae7a74e17b640411a91b2"+[[package]]+name = "blake3"+version = "1.8.7"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "6d9e454fc11f76977dc803893aff6304ed33d6a26efae8696573bea74baa27ae"+dependencies = [+ "arrayvec",+ "cc",+ "cfg-if",+ "constant_time_eq",+ "cpufeatures 0.3.1",+]+[[package]]name = "block"version = "0.1.6"@@ -1821,6 +1834,7 @@ version = "0.1.0"dependencies = ["anyhow","ashpd",+ "blake3","cap-audio","cap-camera","cap-camera-ffmpeg",@@ -2448,6 +2462,12 @@ dependencies = ["tiny-keccak",]+[[package]]+name = "constant_time_eq"+version = "0.4.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b"+[[package]]name = "convert_case"version = "0.4.0"@@ -2727,6 +2747,15 @@ dependencies = ["libc",]+[[package]]+name = "cpufeatures"+version = "0.3.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566"+dependencies = [+ "libc",+]+[[package]]name = "crash-context"version = "0.6.3"@@ -9551,7 +9580,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba"dependencies = ["cfg-if",- "cpufeatures",+ "cpufeatures 0.2.17","digest",]@@ -9562,7 +9591,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"dependencies = ["cfg-if",- "cpufeatures",+ "cpufeatures 0.2.17","digest",]diff --git a/apps/desktop-gpui/Cargo.lock b/apps/desktop-gpui/Cargo.lockindex 89b135e3d..d69344d54 100644--- a/apps/desktop-gpui/Cargo.lock+++ b/apps/desktop-gpui/Cargo.lock@@ -1144,6 +1144,19 @@ dependencies = ["no_std_io2",]+[[package]]+name = "blake3"+version = "1.8.7"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "6d9e454fc11f76977dc803893aff6304ed33d6a26efae8696573bea74baa27ae"+dependencies = [+ "arrayvec",+ "cc",+ "cfg-if",+ "constant_time_eq",+ "cpufeatures 0.3.0",+]+[[package]]name = "block"version = "0.1.6"@@ -1807,6 +1820,7 @@ version = "0.1.0"dependencies = ["anyhow","ashpd 0.11.1",+ "blake3","cap-audio","cap-camera","cap-camera-ffmpeg",@@ -2404,6 +2418,12 @@ dependencies = ["tiny-keccak",]+[[package]]+name = "constant_time_eq"+version = "0.4.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b"+[[package]]name = "convert_case"version = "0.4.0"diff --git a/crates/recording/Cargo.toml b/crates/recording/Cargo.tomlindex c1097b4c3..7b8ed01b5 100644--- a/crates/recording/Cargo.toml+++ b/crates/recording/Cargo.toml@@ -51,6 +51,7 @@ either = "1.13.0"tracing-subscriber = { version = "0.3.19" }relative-path = "1.9.3"tokio-util = "0.7.15"+blake3 = "1.8.2"sha2 = "0.10.9"hex = "0.4.3"ringbuf = "0.4.8"diff --git a/crates/recording/src/recovery.rs b/crates/recording/src/recovery.rsindex b40777558..af0f6c990 100644--- a/crates/recording/src/recovery.rs+++ b/crates/recording/src/recovery.rs@@ -2358,7 +2358,6 @@ fn copy_recovery_input(source: &Path, destination: &Path) -> Result<(), Recoveryfn recovery_snapshot(project: &Path,) -> Result<std::collections::BTreeMap<PathBuf, Option<Vec<u8>>>, RecoveryError> {- use sha2::Digest;fn visit(root: &Path,path: &Path,@@ -2376,7 +2375,7 @@ fn recovery_snapshot(visit(root, &entry?.path(), entries)?;}} else if metadata.is_file() {- let mut digest = sha2::Sha256::new();+ let mut digest = blake3::Hasher::new();use std::io::Read;let mut input = std::fs::File::open(path)?;let mut buffer = [0_u8; 65536];@@ -2387,7 +2386,7 @@ fn recovery_snapshot(}digest.update(&buffer[..count]);}- let _ = entries.insert(relative, Some(digest.finalize().to_vec()));+ let _ = entries.insert(relative, Some(digest.finalize().as_bytes().to_vec()));} else {return Err(RecoveryError::Validation(format!("Unsupported recovery input: {}",@@ -3405,8 +3404,6 @@ mod transactional_recovery_tests {#[test]fn interrupted_rollback_reconciles_and_relaunches_at_every_rename_boundary() {- use sha2::Digest;-for had_config in [false, true] {for failure in 2..=4 {let last_rollback = match failure {@@ -3449,10 +3446,10 @@ mod transactional_recovery_tests {if let (Ok(relative), Some(bytes)) =(path.strip_prefix("content/segments"), bytes){- let actual_digest = sha2::Sha256::digest(- std::fs::read(raw.join(relative)).unwrap(),- )- .to_vec();+ let actual_digest =+ blake3::hash(&std::fs::read(raw.join(relative)).unwrap())+ .as_bytes()+ .to_vec();assert_eq!(&actual_digest, bytes);}}@@ -4012,7 +4009,19 @@ mod transactional_recovery_tests {fn recovery_source_snapshot_detects_bytes_and_whole_segment_changes() {let (_temporary, project, _workspace) = publication_fixture();let before = recovery_snapshot(&project).unwrap();- std::fs::write(project.join("content/segments/raw.m4s"), b"different raw").unwrap();+ let raw = project.join("content/segments/raw.m4s");+ let modified = std::fs::metadata(&raw).unwrap().modified().unwrap();+ std::fs::write(&raw, b"modified raw").unwrap();+ std::fs::OpenOptions::new()+ .write(true)+ .open(&raw)+ .unwrap()+ .set_times(std::fs::FileTimes::new().set_modified(modified))+ .unwrap();+ assert_eq!(+ std::fs::metadata(&raw).unwrap().modified().unwrap(),+ modified+ );assert_ne!(recovery_snapshot(&project).unwrap(), before);std::fs::write(project.join("content/segments/raw.m4s"), b"original raw").unwrap();assert_eq!(recovery_snapshot(&project).unwrap(), before);