perf: use Arc<str> for repetitive DTO fields to eliminate clone allocations

Replace String with Arc<str> for fields that contain repeated static
values (mime_type, icon_class, icon_special_class, category) in
FileDto, FolderDto, and OptimizedFileContent.

These fields are computed from ~40 static lookup tables and cloned
on every request. With Arc<str>, clone becomes O(1) atomic increment
instead of O(n) heap allocation — saving thousands of allocations/s
under load.

Fields kept as String: id, name, path, folder_id, owner_id
(unique per item, rarely cloned).

Zero API impact — serde serializes Arc<str> identically to String.

https://claude.ai/code/session_01EbAFEfyJNLRmJHmmYDX3Tt
This commit is contained in:
Claude
2026-03-03 15:55:15 +00:00
parent 4bee05c690
commit 78c983136f
9 changed files with 52 additions and 47 deletions
@@ -61,7 +61,7 @@ impl FileRetrievalService {
mime: &str,
file_size: u64,
accept_webp: bool,
) -> Option<(Bytes, String)> {
) -> Option<(Bytes, Arc<str>)> {
if !accept_webp {
return None;
}
@@ -81,7 +81,7 @@ impl FileRetrievalService {
transcoded.len(),
(1.0 - transcoded.len() as f64 / content.len().max(1) as f64) * 100.0
);
Some((transcoded, webp_mime))
Some((transcoded, Arc::from(&*webp_mime)))
}
_ => None,
}
@@ -152,7 +152,7 @@ impl FileRetrievalService {
// Store in cache
if let Some(cache) = &self.content_cache {
let etag: Arc<str> = format!("\"{}-{}\"", id, modified_at).into();
let ct: Arc<str> = Arc::from(&*mime_type);
let ct: Arc<str> = mime_type.clone();
cache
.put(id.to_string(), content_bytes.clone(), etag, ct)
.await;
+1 -1
View File
@@ -158,7 +158,7 @@ impl SearchService {
name: file.name.clone(),
path: file.path.clone(),
size: file.size,
mime_type: file.mime_type.clone(),
mime_type: file.mime_type.to_string(),
folder_id: file.folder_id.clone(),
created_at: file.created_at,
modified_at: file.modified_at,