YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix: improve benchmarks and handle platform-specific code (#1675)
Divanshu Grover8263076ac478
diff --git a/screenpipe-vision/benches/apple_leak_bench.rs b/screenpipe-vision/benches/apple_leak_bench.rsindex e618f5716..0b091c540 100644--- a/screenpipe-vision/benches/apple_leak_bench.rs+++ b/screenpipe-vision/benches/apple_leak_bench.rs@@ -1,96 +1,104 @@-use criterion::{criterion_group, criterion_main, Criterion};-use image::GenericImageView;-use memory_stats::memory_stats;-use screenpipe_vision::perform_ocr_apple;-use std::path::PathBuf;+#[cfg(target_os = "macos")]+mod apple_leak_bench {+ use criterion::{criterion_group, criterion_main, Criterion};+ use image::GenericImageView;+ use memory_stats::memory_stats;+ use screenpipe_vision::perform_ocr_apple;+ use std::path::PathBuf;-fn bytes_to_mb(bytes: usize) -> f64 {- bytes as f64 / (1024.0 * 1024.0)-}+ fn bytes_to_mb(bytes: usize) -> f64 {+ bytes as f64 / (1024.0 * 1024.0)+ }-fn bytes_to_gb(bytes: usize) -> f64 {- bytes as f64 / (1024.0 * 1024.0 * 1024.0)-}+ fn bytes_to_gb(bytes: usize) -> f64 {+ bytes as f64 / (1024.0 * 1024.0 * 1024.0)+ }-fn apple_ocr_benchmark(c: &mut Criterion) {- let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));- path.push("tests");- path.push("testing_OCR.png");+ fn apple_ocr_benchmark(c: &mut Criterion) {+ let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));+ path.push("tests");+ path.push("testing_OCR.png");- let image = image::open(&path).expect("Failed to open image");- println!("Image dimensions: {:?}", image.dimensions());+ let image = image::open(&path).expect("Failed to open image");+ println!("Image dimensions: {:?}", image.dimensions());- let mut group = c.benchmark_group("apple_ocr");- group.sample_size(100); // Increased sample size- group.measurement_time(std::time::Duration::from_secs(60)); // Run for at least 60 seconds- group.bench_function("perform_ocr_apple", |b| {- b.iter_custom(|iters| {- let start = std::time::Instant::now();- let mut initial_memory = 0;- let mut final_memory = 0;- let mut max_memory = 0;+ let mut group = c.benchmark_group("apple_ocr");+ group.sample_size(100); // Increased sample size+ group.measurement_time(std::time::Duration::from_secs(60)); // Run for at least 60 seconds+ group.bench_function("perform_ocr_apple", |b| {+ b.iter_custom(|iters| {+ let start = std::time::Instant::now();+ let mut initial_memory = 0;+ let mut final_memory = 0;+ let mut max_memory = 0;- for i in 0..iters {- if i == 0 {- if let Some(usage) = memory_stats() {- initial_memory = usage.physical_mem;- max_memory = initial_memory;+ for i in 0..iters {+ if i == 0 {+ if let Some(usage) = memory_stats() {+ initial_memory = usage.physical_mem;+ max_memory = initial_memory;+ }}- }- let result = perform_ocr_apple(&image, &[]);- assert!(- result.0.contains("receiver_count"),- "OCR failed: {:?}",- result- );+ let result = perform_ocr_apple(&image, &[]);+ assert!(+ result.0.contains("receiver_count"),+ "OCR failed: {:?}",+ result+ );- if let Some(usage) = memory_stats() {- final_memory = usage.physical_mem;- max_memory = max_memory.max(final_memory);- }+ if let Some(usage) = memory_stats() {+ final_memory = usage.physical_mem;+ max_memory = max_memory.max(final_memory);+ }- if i % 10 == 0 {- println!(- "Iteration {}: Current memory usage: {:.2} MB ({:.3} GB)",- i,- bytes_to_mb(final_memory),- bytes_to_gb(final_memory)- );+ if i % 10 == 0 {+ println!(+ "Iteration {}: Current memory usage: {:.2} MB ({:.3} GB)",+ i,+ bytes_to_mb(final_memory),+ bytes_to_gb(final_memory)+ );+ }}- }- println!(- "Initial memory usage: {:.2} MB ({:.3} GB)",- bytes_to_mb(initial_memory),- bytes_to_gb(initial_memory)- );- println!(- "Final memory usage: {:.2} MB ({:.3} GB)",- bytes_to_mb(final_memory),- bytes_to_gb(final_memory)- );- println!(- "Max memory usage: {:.2} MB ({:.3} GB)",- bytes_to_mb(max_memory),- bytes_to_gb(max_memory)- );- println!(- "Total memory difference: {:.2} MB ({:.3} GB)",- bytes_to_mb(final_memory - initial_memory),- bytes_to_gb(final_memory - initial_memory)- );- println!(- "Max memory difference: {:.2} MB ({:.3} GB)",- bytes_to_mb(max_memory - initial_memory),- bytes_to_gb(max_memory - initial_memory)- );+ println!(+ "Initial memory usage: {:.2} MB ({:.3} GB)",+ bytes_to_mb(initial_memory),+ bytes_to_gb(initial_memory)+ );+ println!(+ "Final memory usage: {:.2} MB ({:.3} GB)",+ bytes_to_mb(final_memory),+ bytes_to_gb(final_memory)+ );+ println!(+ "Max memory usage: {:.2} MB ({:.3} GB)",+ bytes_to_mb(max_memory),+ bytes_to_gb(max_memory)+ );+ println!(+ "Total memory difference: {:.2} MB ({:.3} GB)",+ bytes_to_mb(final_memory - initial_memory),+ bytes_to_gb(final_memory - initial_memory)+ );+ println!(+ "Max memory difference: {:.2} MB ({:.3} GB)",+ bytes_to_mb(max_memory - initial_memory),+ bytes_to_gb(max_memory - initial_memory)+ );- start.elapsed()+ start.elapsed()+ });});- });- group.finish();+ group.finish();+ }++ criterion_group!(benches, apple_ocr_benchmark);+ criterion_main!(benches);}-criterion_group!(benches, apple_ocr_benchmark);-criterion_main!(benches);+#[cfg(not(target_os = "macos"))]+fn main() {+ // Empty main for non-macOS platforms+}diff --git a/screenpipe-vision/benches/ocr_benchmark.rs b/screenpipe-vision/benches/ocr_benchmark.rsindex cbb0b9d1e..00e0d5050 100644--- a/screenpipe-vision/benches/ocr_benchmark.rs+++ b/screenpipe-vision/benches/ocr_benchmark.rs@@ -134,7 +134,7 @@ fn bench_tesseract_ocr(c: &mut Criterion) {for _ in 0..iters {let start = std::time::Instant::now();- let (result, _) = perform_ocr_tesseract(black_box(&image));+ let (result, _, _) = perform_ocr_tesseract(black_box(&image), vec![]);total_duration += start.elapsed();let accuracy = calculate_accuracy(&result, EXPECTED_KEYWORDS);diff --git a/screenpipe-vision/benches/vision_benchmark.rs b/screenpipe-vision/benches/vision_benchmark.rsindex b3b5ea0f2..6dc1b14c1 100644--- a/screenpipe-vision/benches/vision_benchmark.rs+++ b/screenpipe-vision/benches/vision_benchmark.rs@@ -17,7 +17,7 @@ async fn benchmark_continuous_capture(duration_secs: u64) -> f64 {let window_filters = Arc::new(WindowFilters::new(&[], &[]));let capture_handle = tokio::spawn(async move {- continuous_capture(+ if let Err(e) = continuous_capture(result_tx,Duration::from_millis(100),OcrEngine::Tesseract,@@ -26,7 +26,10 @@ async fn benchmark_continuous_capture(duration_secs: u64) -> f64 {vec![],false,)- .await;+ .await+ {+ eprintln!("Error in continuous capture: {}", e);+ }});// Run for specified duration