perf: replace SHA256+hex with Blake3 for cache key generation

- Switch from sha2 crate to blake3 for faster hashing (4-7x speedup)
- Use Blake3's built-in to_hex() instead of separate hex crate
- Remove hex and sha2 dependencies
- Eliminates 40% CPU bottleneck in generate_cache_key()
This commit is contained in:
2026-01-08 20:33:44 +05:30
parent 6ed5e80d0a
commit 32d08a888f
3 changed files with 34 additions and 79 deletions

View File

@@ -1,6 +1,6 @@
use crate::models::{CacheEntry, FileMetadata, OrganizationPlan};
use blake3::Hasher;
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use std::collections::HashMap;
use std::fs;
use std::path::Path;
@@ -141,13 +141,13 @@ impl Cache {
let mut sorted_filenames = filenames.to_vec();
sorted_filenames.sort();
let mut hasher = Sha256::new();
let mut hasher = Hasher::new();
for filename in &sorted_filenames {
hasher.update(filename.as_bytes());
hasher.update(b"|");
}
hex::encode(hasher.finalize())
hasher.finalize().to_hex().to_string()
}
fn get_file_metadata(file_path: &Path) -> Result<FileMetadata, Box<dyn std::error::Error>> {