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:
+27
-21
@@ -3,6 +3,8 @@
|
||||
//! This module contains error types specific to the HTTP/API layer.
|
||||
//! These errors handle the conversion from domain errors to HTTP responses.
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
use axum::Json;
|
||||
use axum::http::StatusCode;
|
||||
use axum::response::{IntoResponse, Response};
|
||||
@@ -13,25 +15,28 @@ use crate::domain::errors::{DomainError, ErrorKind};
|
||||
/// Error type for HTTP/API responses.
|
||||
///
|
||||
/// This struct represents errors that will be returned to HTTP clients.
|
||||
/// It contains the HTTP status code, a user-friendly message, and an error type identifier.
|
||||
/// It contains the HTTP status code, a user-friendly message, and an error
|
||||
/// type identifier. `error_type` is a `Cow`: every built-in constructor and
|
||||
/// the `DomainError` conversion use a `&'static str` from a closed set, so
|
||||
/// the common 4xx path allocates nothing for it (benches/ROUND11.md §9).
|
||||
#[derive(Debug)]
|
||||
pub struct AppError {
|
||||
pub status_code: StatusCode,
|
||||
pub message: String,
|
||||
pub error_type: String,
|
||||
pub error_type: Cow<'static, str>,
|
||||
}
|
||||
|
||||
/// JSON response structure for errors.
|
||||
///
|
||||
/// Both `error` and `message` carry the same content for backwards compatibility:
|
||||
/// - Legacy ad-hoc handlers returned `{"error": "..."}` (frontend reads `.error`)
|
||||
/// - AppError returned `{"message": "..."}` (admin panel reads `.message`)
|
||||
/// JSON response structure for errors, borrowing from the `AppError` it
|
||||
/// renders — `error` and `message` intentionally serialize the SAME string
|
||||
/// for backwards compatibility (legacy handlers returned `{"error": …}`,
|
||||
/// AppError returned `{"message": …}`); serializing one buffer twice
|
||||
/// replaces the old per-response deep clone.
|
||||
#[derive(Serialize)]
|
||||
pub struct ErrorResponse {
|
||||
pub status: String,
|
||||
pub error: String,
|
||||
pub message: String,
|
||||
pub error_type: String,
|
||||
pub struct ErrorResponse<'a> {
|
||||
pub status: &'a str,
|
||||
pub error: &'a str,
|
||||
pub message: &'a str,
|
||||
pub error_type: &'a str,
|
||||
}
|
||||
|
||||
impl AppError {
|
||||
@@ -39,7 +44,7 @@ impl AppError {
|
||||
pub fn new(
|
||||
status_code: StatusCode,
|
||||
message: impl Into<String>,
|
||||
error_type: impl Into<String>,
|
||||
error_type: impl Into<Cow<'static, str>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
status_code,
|
||||
@@ -131,7 +136,7 @@ impl From<DomainError> for AppError {
|
||||
Self {
|
||||
status_code,
|
||||
message: err.message,
|
||||
error_type: err.kind.to_string(),
|
||||
error_type: Cow::Borrowed(err.kind.as_str()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -144,25 +149,26 @@ impl IntoResponse for AppError {
|
||||
// Log the full error server-side for debugging, return a generic
|
||||
// message to the client. Other status codes (including 5xx like
|
||||
// 501, 503, 507) keep their intentionally user-facing messages.
|
||||
let client_message = if status == StatusCode::INTERNAL_SERVER_ERROR {
|
||||
let client_message: &str = if status == StatusCode::INTERNAL_SERVER_ERROR {
|
||||
tracing::error!(
|
||||
error_type = %self.error_type,
|
||||
"Internal server error: {}",
|
||||
self.message
|
||||
);
|
||||
"An internal error occurred. Please try again later.".to_string()
|
||||
"An internal error occurred. Please try again later."
|
||||
} else {
|
||||
self.message
|
||||
&self.message
|
||||
};
|
||||
|
||||
let status_line = status.to_string();
|
||||
let error_response = ErrorResponse {
|
||||
status: status.to_string(),
|
||||
error: client_message.clone(),
|
||||
status: &status_line,
|
||||
error: client_message,
|
||||
message: client_message,
|
||||
error_type: self.error_type,
|
||||
error_type: &self.error_type,
|
||||
};
|
||||
|
||||
let body = Json(error_response);
|
||||
let body = Json(&error_response);
|
||||
(status, body).into_response()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user