perf: round 11 — StoragePath joined-only, classifier fusion, memoized bodies, query-shape pack, SPA fine-grained stars
Backend (each change benchmark-gated with BEFORE replicas + equivalence gates; see examples/bench_round11_micro.rs, bench_round11_queries.rs, bench_log_writer.rs and benches/ROUND11.md — final numbers land in the follow-up doc commit): - StoragePath re-representation: single canonical joined String, segments derived on demand; File/Folder drop the duplicated path_string field (4000→1000 allocs per 500-row listing page) - Display classifier fusion: classify_display shares one stack-lowered extension across the three decision trees; call sites in FileDto, folder/favorites/recent handlers, trash, path-resolver (+ interning where Arc::from was still used) - /status.php and /openapi.json memoized into OnceLock<Bytes> (openapi rebuilt a 171 KiB spec per request: 2.8 ms → 18 ns) - NC upload-session PROPFIND: write! + pre-sized body + stack RFC2822 dates (2.3-2.6x, 2582→772 allocs at 256 chunks) - REST download: dead FileDto clone removed (capture mime/size + move) - CalendarEventDto/TrashedItem into_parts moves (11 KiB ical_data memcpy gone per CalDAV row); CardDAV getlastmodified stack render - 4xx path: borrowed ErrorResponse serialize, ErrorKind::as_str, not_found/already_exists clone kill - vCard emit via write!; search page moved out with into_iter skip/take; content-hit UUIDs parsed once; group last-user check via HashSet - RateLimiter: lock-free get + insert (and_upsert_with variant REJECTED by benchmark); CSRF token borrow-compare + borrowed cookie extraction - Thumbnail/preview ETags built from as_str (Debug-identical bytes) - Encrypted backend: encrypt_in_place_detached single-buffer write path, chunk-sized reserve in collect_stream; retry labels made lazy - PG: deferred upload registration 3→1 round-trips (persist_file CTE template); direct_grant_cache for Calendar/AddressBook/Playlist authz (single-flight + set_role/clear_role invalidation); expand_user tokio::join!; geo clusters min(uuid)::text; recluster face assignment batched into one UNNEST update - People recluster cosine: norms precomputed once (bit-identical gate) - NC capabilities poll logs demoted to debug; tracing-appender dep added for the log-writer benchmark Frontend: - ResourceList.selectedEntries O(N)-per-toggle → id-index projection O(k log k); favorites/recent consume the batchToolbar snippet param and drop their duplicate filter + dead selectedIds mirror - Recent: star state via new favoriteIds prop — a star click no longer rebuilds all N entries - admin timeAgo >30d fallback uses the cached Intl.DateTimeFormat - vitest gates in src/lib/components/round11.bench.test.ts Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ABhTEHuGujvwoodh67Kga7
This commit is contained in:
@@ -132,21 +132,26 @@ impl Default for CalendarEventDto {
|
||||
|
||||
impl From<CalendarEvent> for CalendarEventDto {
|
||||
fn from(event: CalendarEvent) -> Self {
|
||||
// Move every owned field out of the consumed entity — the old
|
||||
// getter-clone shape deep-copied 6 Strings per event, dominated by
|
||||
// the ~11 KB `ical_data` blob, on every CalDAV listing row
|
||||
// (benches/ROUND11.md §19: 1.45x + the 11 KB memcpy gone).
|
||||
let parts = event.into_parts();
|
||||
Self {
|
||||
id: event.id().to_string(),
|
||||
calendar_id: event.calendar_id().to_string(),
|
||||
summary: event.summary().to_string(),
|
||||
description: event.description().map(|s| s.to_string()),
|
||||
location: event.location().map(|s| s.to_string()),
|
||||
start_time: *event.start_time(),
|
||||
end_time: *event.end_time(),
|
||||
all_day: event.all_day(),
|
||||
rrule: event.rrule().map(|s| s.to_string()),
|
||||
ical_uid: event.ical_uid().to_string(),
|
||||
recurrence_id: event.recurrence_id().copied(),
|
||||
ical_data: event.ical_data().to_string(),
|
||||
created_at: *event.created_at(),
|
||||
updated_at: *event.updated_at(),
|
||||
id: parts.id.to_string(),
|
||||
calendar_id: parts.calendar_id.to_string(),
|
||||
summary: parts.summary,
|
||||
description: parts.description,
|
||||
location: parts.location,
|
||||
start_time: parts.start_time,
|
||||
end_time: parts.end_time,
|
||||
all_day: parts.all_day,
|
||||
rrule: parts.rrule,
|
||||
ical_uid: parts.ical_uid,
|
||||
recurrence_id: parts.recurrence_id,
|
||||
ical_data: parts.ical_data,
|
||||
created_at: parts.created_at,
|
||||
updated_at: parts.updated_at,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,6 +188,50 @@ fn ext_of(name: &str) -> Option<&str> {
|
||||
Some(after_dot)
|
||||
}
|
||||
|
||||
/// Longest extension any classifier table matches ("appimage", "markdown"
|
||||
/// — 8 bytes). Longer extensions can only ever hit the `_` arms, so they
|
||||
/// skip the buffer entirely.
|
||||
const MAX_CLASSIFIED_EXT: usize = 16;
|
||||
|
||||
/// Lowercase `ext` into `buf` without heap allocation. Returns `None` for
|
||||
/// extensions longer than any table entry — the caller must then take the
|
||||
/// same default arm `ext.to_ascii_lowercase()` would have fallen into.
|
||||
fn lower_ext_into<'b>(ext: &str, buf: &'b mut [u8; MAX_CLASSIFIED_EXT]) -> Option<&'b str> {
|
||||
let bytes = ext.as_bytes();
|
||||
if bytes.len() > MAX_CLASSIFIED_EXT {
|
||||
return None;
|
||||
}
|
||||
for (i, b) in bytes.iter().enumerate() {
|
||||
buf[i] = b.to_ascii_lowercase();
|
||||
}
|
||||
// ASCII-lowercasing bytes keeps UTF-8 validity (non-ASCII bytes pass
|
||||
// through untouched).
|
||||
std::str::from_utf8(&buf[..bytes.len()]).ok()
|
||||
}
|
||||
|
||||
/// The three display classifications for one `(name, mime)` pair.
|
||||
pub struct DisplayClass {
|
||||
pub icon_class: &'static str,
|
||||
pub icon_special_class: &'static str,
|
||||
pub category: &'static str,
|
||||
}
|
||||
|
||||
/// Run all three classifiers over one `(name, mime)` pair, lowering the
|
||||
/// extension **once into a stack buffer** instead of each classifier
|
||||
/// allocating its own `to_ascii_lowercase()` String on the fallback path
|
||||
/// (generic/empty MIME rows — common for code and unknown types). Each
|
||||
/// decision tree is byte-for-byte the classifier it replaces
|
||||
/// (benches/ROUND11.md §21 gates the equivalence over a corpus).
|
||||
pub fn classify_display(name: &str, mime: &str) -> DisplayClass {
|
||||
let mut buf = [0u8; MAX_CLASSIFIED_EXT];
|
||||
let ext = ext_of(name).and_then(|e| lower_ext_into(e, &mut buf));
|
||||
DisplayClass {
|
||||
icon_class: icon_class_with_ext(mime, ext),
|
||||
icon_special_class: icon_special_class_with_ext(mime, ext),
|
||||
category: category_with_ext(mime, ext),
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Icon class (FontAwesome) ────────────────────────────────────────
|
||||
|
||||
/// Returns the FontAwesome icon class for a file, considering both MIME
|
||||
@@ -196,6 +240,12 @@ fn ext_of(name: &str) -> Option<&str> {
|
||||
/// Use this instead of the old `mime_to_icon_class` whenever the filename
|
||||
/// is available.
|
||||
pub fn icon_class_for(name: &str, mime: &str) -> &'static str {
|
||||
let mut buf = [0u8; MAX_CLASSIFIED_EXT];
|
||||
let ext = ext_of(name).and_then(|e| lower_ext_into(e, &mut buf));
|
||||
icon_class_with_ext(mime, ext)
|
||||
}
|
||||
|
||||
fn icon_class_with_ext(mime: &str, ext: Option<&str>) -> &'static str {
|
||||
// 1. Try specific MIME matches first
|
||||
match mime {
|
||||
"application/pdf" => return "fas fa-file-pdf",
|
||||
@@ -273,8 +323,8 @@ pub fn icon_class_for(name: &str, mime: &str) -> &'static str {
|
||||
}
|
||||
|
||||
// 3. Extension-based fallback (for application/octet-stream, empty, etc.)
|
||||
if let Some(ext) = ext_of(name) {
|
||||
return match ext.to_ascii_lowercase().as_str() {
|
||||
if let Some(ext) = ext {
|
||||
return match ext {
|
||||
"pdf" => "fas fa-file-pdf",
|
||||
"doc" | "docx" | "odt" | "rtf" => "fas fa-file-word",
|
||||
"xls" | "xlsx" | "ods" | "csv" => "fas fa-file-excel",
|
||||
@@ -311,6 +361,12 @@ pub fn icon_class_for(name: &str, mime: &str) -> &'static str {
|
||||
/// The returned class maps to CSS rules in `style.css` that set colours,
|
||||
/// backgrounds and decorative pseudo-elements per file type.
|
||||
pub fn icon_special_class_for(name: &str, mime: &str) -> &'static str {
|
||||
let mut buf = [0u8; MAX_CLASSIFIED_EXT];
|
||||
let ext = ext_of(name).and_then(|e| lower_ext_into(e, &mut buf));
|
||||
icon_special_class_with_ext(mime, ext)
|
||||
}
|
||||
|
||||
fn icon_special_class_with_ext(mime: &str, ext: Option<&str>) -> &'static str {
|
||||
// 1. Specific MIME matches
|
||||
match mime {
|
||||
"application/pdf" => return "pdf-icon",
|
||||
@@ -390,8 +446,8 @@ pub fn icon_special_class_for(name: &str, mime: &str) -> &'static str {
|
||||
}
|
||||
|
||||
// 3. Extension-based fallback
|
||||
if let Some(ext) = ext_of(name) {
|
||||
return match ext.to_ascii_lowercase().as_str() {
|
||||
if let Some(ext) = ext {
|
||||
return match ext {
|
||||
"pdf" => "pdf-icon",
|
||||
"doc" | "docx" | "odt" | "rtf" => "doc-icon",
|
||||
"xls" | "xlsx" | "ods" | "csv" => "spreadsheet-icon",
|
||||
@@ -437,6 +493,12 @@ pub fn icon_special_class_for(name: &str, mime: &str) -> &'static str {
|
||||
|
||||
/// Returns a human-readable category label, considering MIME + extension.
|
||||
pub fn category_for(name: &str, mime: &str) -> &'static str {
|
||||
let mut buf = [0u8; MAX_CLASSIFIED_EXT];
|
||||
let ext = ext_of(name).and_then(|e| lower_ext_into(e, &mut buf));
|
||||
category_with_ext(mime, ext)
|
||||
}
|
||||
|
||||
fn category_with_ext(mime: &str, ext: Option<&str>) -> &'static str {
|
||||
// 1. Specific MIME matches
|
||||
match mime {
|
||||
"application/pdf" => return "PDF",
|
||||
@@ -489,8 +551,8 @@ pub fn category_for(name: &str, mime: &str) -> &'static str {
|
||||
}
|
||||
|
||||
// 3. Extension fallback
|
||||
if let Some(ext) = ext_of(name) {
|
||||
return match ext.to_ascii_lowercase().as_str() {
|
||||
if let Some(ext) = ext {
|
||||
return match ext {
|
||||
"pdf" => "PDF",
|
||||
"doc" | "docx" | "odt" | "rtf" | "txt" => "Document",
|
||||
"xls" | "xlsx" | "ods" | "csv" => "Spreadsheet",
|
||||
|
||||
@@ -4,9 +4,7 @@ use utoipa::{IntoParams, ToSchema};
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::cursor::{CursorListResponse, CursorQuery, PageCursor};
|
||||
use super::display_helpers::{
|
||||
category_for, format_file_size, icon_class_for, icon_special_class_for,
|
||||
};
|
||||
use super::display_helpers::{classify_display, format_file_size};
|
||||
use super::grant_dto::{ResourceContentDto, ResourceTypeDto};
|
||||
use crate::domain::services::authorization::ResourceKind;
|
||||
|
||||
@@ -84,9 +82,10 @@ impl FavoriteItemDto {
|
||||
.item_mime_type
|
||||
.as_deref()
|
||||
.unwrap_or("application/octet-stream");
|
||||
self.icon_class = icon_class_for(name, mime).to_string();
|
||||
self.icon_special_class = icon_special_class_for(name, mime).to_string();
|
||||
self.category = category_for(name, mime).to_string();
|
||||
let classes = classify_display(name, mime);
|
||||
self.icon_class = classes.icon_class.to_string();
|
||||
self.icon_special_class = classes.icon_special_class.to_string();
|
||||
self.category = classes.category.to_string();
|
||||
self.size_formatted = format_file_size(self.item_size.unwrap_or(0) as u64);
|
||||
}
|
||||
self
|
||||
|
||||
@@ -5,10 +5,7 @@ use serde::{Deserialize, Serialize};
|
||||
use utoipa::ToSchema;
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::display_helpers::{
|
||||
category_for, format_file_size, icon_class_for, icon_special_class_for, intern_display,
|
||||
intern_mime,
|
||||
};
|
||||
use super::display_helpers::{classify_display, format_file_size, intern_display, intern_mime};
|
||||
|
||||
/// DTO for file responses
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
|
||||
@@ -105,17 +102,17 @@ impl From<File> for FileDto {
|
||||
// Display fields come from closed static tables and MIME values
|
||||
// repeat massively across rows — intern instead of allocating a
|
||||
// fresh Arc<str> per row (`Arc::from(&str)` always allocs+copies).
|
||||
let icon_class = intern_display(icon_class_for(&parts.name, &parts.mime_type));
|
||||
let icon_special_class =
|
||||
intern_display(icon_special_class_for(&parts.name, &parts.mime_type));
|
||||
let category = intern_display(category_for(&parts.name, &parts.mime_type));
|
||||
let classes = classify_display(&parts.name, &parts.mime_type);
|
||||
let icon_class = intern_display(classes.icon_class);
|
||||
let icon_special_class = intern_display(classes.icon_special_class);
|
||||
let category = intern_display(classes.category);
|
||||
let size_formatted = format_file_size(parts.size);
|
||||
let mime_type = intern_mime(&parts.mime_type);
|
||||
|
||||
Self {
|
||||
id: parts.id,
|
||||
name: parts.name,
|
||||
path: parts.path_string,
|
||||
path: parts.storage_path.into_joined(),
|
||||
size: parts.size,
|
||||
mime_type,
|
||||
folder_id: parts.folder_id,
|
||||
|
||||
@@ -113,7 +113,7 @@ impl From<Folder> for FolderDto {
|
||||
Self {
|
||||
id: parts.id,
|
||||
name: parts.name,
|
||||
path: parts.path_string,
|
||||
path: parts.storage_path.into_joined(),
|
||||
parent_id: parts.parent_id,
|
||||
drive_id: parts.drive_id,
|
||||
created_at: parts.created_at,
|
||||
|
||||
@@ -4,9 +4,7 @@ use utoipa::{IntoParams, ToSchema};
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::cursor::{CursorListResponse, CursorQuery, PageCursor};
|
||||
use super::display_helpers::{
|
||||
category_for, format_file_size, icon_class_for, icon_special_class_for,
|
||||
};
|
||||
use super::display_helpers::{classify_display, format_file_size};
|
||||
use super::grant_dto::{ResourceContentDto, ResourceTypeDto};
|
||||
use crate::domain::services::authorization::ResourceKind;
|
||||
|
||||
@@ -80,9 +78,10 @@ impl RecentItemDto {
|
||||
.item_mime_type
|
||||
.as_deref()
|
||||
.unwrap_or("application/octet-stream");
|
||||
self.icon_class = icon_class_for(name, mime).to_string();
|
||||
self.icon_special_class = icon_special_class_for(name, mime).to_string();
|
||||
self.category = category_for(name, mime).to_string();
|
||||
let classes = classify_display(name, mime);
|
||||
self.icon_class = classes.icon_class.to_string();
|
||||
self.icon_special_class = classes.icon_special_class.to_string();
|
||||
self.category = classes.category.to_string();
|
||||
self.size_formatted = format_file_size(self.item_size.unwrap_or(0) as u64);
|
||||
}
|
||||
self
|
||||
|
||||
Reference in New Issue
Block a user