From 433d36aea8bf77a284cc6aacf0d65982e8b57aa4 Mon Sep 17 00:00:00 2001 From: ProofOfConcept Date: Sat, 14 Mar 2026 19:27:28 -0400 Subject: [PATCH] evaluate: use rayon par_sort_by for parallel LLM comparisons MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Merge sort parallelizes naturally — multiple LLM comparison calls happen concurrently. Safe because merge sort terminates correctly even with non-deterministic comparators (unlike quicksort). Co-Authored-By: Kent Overstreet --- poc-memory/src/cli/agent.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/poc-memory/src/cli/agent.rs b/poc-memory/src/cli/agent.rs index c81c5db..f805c00 100644 --- a/poc-memory/src/cli/agent.rs +++ b/poc-memory/src/cli/agent.rs @@ -3,6 +3,7 @@ use crate::store; use crate::store::StoreView; use crate::agents::llm; +use std::sync::atomic::{AtomicUsize, Ordering}; pub fn cmd_consolidate_batch(count: usize, auto: bool, agent: Option) -> Result<(), String> { let store = store::Store::load()?; @@ -178,17 +179,18 @@ pub fn cmd_evaluate_agents(samples_per_type: usize, model: &str) -> Result<(), S all_samples.len() * (all_samples.len() as f64).log2() as usize, model); - // Sort with LLM comparator — yes, really. Rust's sort_by with an - // LLM as the comparison function. Each comparison is an API call. - let mut comparisons = 0usize; - all_samples.sort_by(|a, b| { - comparisons += 1; - if comparisons % 10 == 0 { - eprint!(" {} comparisons...\r", comparisons); + // Sort with LLM comparator — yes, really. Rayon's parallel merge sort + // with an LLM as the comparison function. Multiple API calls in parallel. + let comparisons = AtomicUsize::new(0); + use rayon::slice::ParallelSliceMut; + all_samples.par_sort_by(|a, b| { + let n = comparisons.fetch_add(1, Ordering::Relaxed); + if n % 10 == 0 { + eprint!(" {} comparisons...\r", n); } llm_compare(a, b, model).unwrap_or(std::cmp::Ordering::Equal) }); - eprintln!(" {} total comparisons", comparisons); + eprintln!(" {} total comparisons", comparisons.load(Ordering::Relaxed)); let sorted = all_samples;