perf: replace SHA-256 with BLAKE3 + add mimalloc global allocator
- Replace SHA-256 with BLAKE3 (~5x faster) for content-addressable hashing in dedup_service, file_handler, file_upload_service, chunked_upload_service - Add mimalloc as global allocator for 10-30% throughput improvement - sha2 crate retained only for PKCE (OAuth2 standard requirement) - BLAKE3 produces 64-char hex hashes (same format), no DB schema changes needed
This commit is contained in:
@@ -84,7 +84,7 @@ pub trait ChunkedUploadPort: Send + Sync + 'static {
|
||||
|
||||
/// Assemble all chunks into the final file.
|
||||
///
|
||||
/// Returns `(assembled_file_path, filename, folder_id, content_type, total_size, sha256_hash)`.
|
||||
/// Returns `(assembled_file_path, filename, folder_id, content_type, total_size, blake3_hash)`.
|
||||
/// The hash is computed during assembly (hash-on-write), eliminating a
|
||||
/// second sequential read of the assembled file.
|
||||
async fn complete_upload(
|
||||
|
||||
@@ -15,7 +15,7 @@ use std::pin::Pin;
|
||||
/// Metadata of a stored blob in the dedup system.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct BlobMetadataDto {
|
||||
/// SHA-256 hash of the content.
|
||||
/// BLAKE3 hash of the content.
|
||||
pub hash: String,
|
||||
/// Size in bytes.
|
||||
pub size: u64,
|
||||
@@ -151,7 +151,7 @@ pub trait DedupPort: Send + Sync + 'static {
|
||||
/// Returns `true` if the blob was deleted (ref_count reached 0).
|
||||
async fn remove_reference(&self, hash: &str) -> Result<bool, DomainError>;
|
||||
|
||||
/// Calculate SHA-256 hash of a file (streaming).
|
||||
/// Calculate BLAKE3 hash of a file (streaming).
|
||||
async fn hash_file(&self, path: &Path) -> Result<String, DomainError>;
|
||||
|
||||
/// Get deduplication statistics.
|
||||
|
||||
@@ -55,7 +55,7 @@ pub trait FileReadPort: Send + Sync + 'static {
|
||||
|
||||
/// Gets the content-addressable blob hash for a file (O(1) DB lookup).
|
||||
///
|
||||
/// Returns the SHA-256 hash stored in `storage.files.blob_hash`.
|
||||
/// Returns the BLAKE3 hash stored in `storage.files.blob_hash`.
|
||||
/// Used for dedup reference tracking without loading file content.
|
||||
async fn get_blob_hash(&self, file_id: &str) -> Result<String, DomainError>;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use async_trait::async_trait;
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -199,7 +199,7 @@ impl FileUploadUseCase for FileUploadService {
|
||||
tokio::fs::write(temp.path(), content)
|
||||
.await
|
||||
.map_err(|e| DomainError::internal_error("FileUpload", format!("write temp: {e}")))?;
|
||||
let hash = hex::encode(Sha256::digest(content));
|
||||
let hash = blake3::hash(content).to_hex().to_string();
|
||||
|
||||
let file = self
|
||||
.file_write
|
||||
@@ -228,7 +228,7 @@ impl FileUploadUseCase for FileUploadService {
|
||||
tokio::fs::write(temp.path(), content)
|
||||
.await
|
||||
.map_err(|e| DomainError::internal_error("FileUpload", format!("write temp: {e}")))?;
|
||||
let hash = hex::encode(Sha256::digest(content));
|
||||
let hash = blake3::hash(content).to_hex().to_string();
|
||||
|
||||
self.update_file_streaming(
|
||||
path,
|
||||
|
||||
Reference in New Issue
Block a user