perf: replace dyn trait objects with concrete types to eliminate vtable overhead

Remove async-trait dependency and use native Rust async fn in traits.
Replace Arc<dyn Trait> with Arc<ConcreteType> throughout the codebase
to enable monomorphization and eliminate dynamic dispatch overhead.

Key changes:
- Remove write-behind cache (no implementation existed)
- Fix should_transcode static method call
- Use ContactStorageAdapter directly instead of dyn AddressBookUseCase
- Clean up unused trait imports across services and DI

https://claude.ai/code/session_01EbAFEfyJNLRmJHmmYDX3Tt
This commit is contained in:
Claude
2026-03-03 15:36:42 +00:00
parent efcf88c4d7
commit 1b49135ca9
101 changed files with 346 additions and 576 deletions
@@ -1,4 +1,3 @@
use async_trait::async_trait;
use std::result::Result;
use uuid::Uuid;
@@ -7,7 +6,6 @@ use crate::domain::entities::contact::AddressBook;
pub type AddressBookRepositoryResult<T> = Result<T, DomainError>;
#[async_trait]
pub trait AddressBookRepository: Send + Sync + 'static {
async fn create_address_book(
&self,
@@ -1,13 +1,11 @@
use crate::common::errors::DomainError;
use crate::domain::entities::calendar_event::CalendarEvent;
use async_trait::async_trait;
use chrono::{DateTime, Utc};
use uuid::Uuid;
pub type CalendarEventRepositoryResult<T> = Result<T, DomainError>;
/// Repository interface for CalendarEvent entity operations
#[async_trait]
pub trait CalendarEventRepository: Send + Sync + 'static {
/// Creates a new calendar event
async fn create_event(
@@ -1,12 +1,10 @@
use crate::common::errors::DomainError;
use crate::domain::entities::calendar::Calendar;
use async_trait::async_trait;
use uuid::Uuid;
pub type CalendarRepositoryResult<T> = Result<T, DomainError>;
/// Repository interface for Calendar entity operations
#[async_trait]
pub trait CalendarRepository: Send + Sync + 'static {
/// Creates a new calendar
async fn create_calendar(&self, calendar: Calendar) -> CalendarRepositoryResult<Calendar>;
@@ -1,4 +1,3 @@
use async_trait::async_trait;
use std::result::Result;
use uuid::Uuid;
@@ -7,7 +6,6 @@ use crate::domain::entities::contact::{Contact, ContactGroup};
pub type ContactRepositoryResult<T> = Result<T, DomainError>;
#[async_trait]
pub trait ContactRepository: Send + Sync + 'static {
async fn create_contact(&self, contact: Contact) -> ContactRepositoryResult<Contact>;
async fn update_contact(&self, contact: Contact) -> ContactRepositoryResult<Contact>;
@@ -32,7 +30,6 @@ pub trait ContactRepository: Send + Sync + 'static {
) -> ContactRepositoryResult<Vec<Contact>>;
}
#[async_trait]
pub trait ContactGroupRepository: Send + Sync + 'static {
async fn create_group(&self, group: ContactGroup) -> ContactRepositoryResult<ContactGroup>;
async fn update_group(&self, group: ContactGroup) -> ContactRepositoryResult<ContactGroup>;
@@ -10,7 +10,6 @@
use std::path::PathBuf;
use async_trait::async_trait;
use bytes::Bytes;
use futures::Stream;
@@ -26,7 +25,6 @@ use crate::domain::services::path_service::StoragePath;
///
/// Encapsulates every operation that queries state without modifying it:
/// get, list, content, stream, mmap, range, path resolution.
#[async_trait]
pub trait FileReadRepository: Send + Sync + 'static {
/// Gets a file by its ID.
async fn get_file(&self, id: &str) -> Result<File, DomainError>;
@@ -63,7 +61,6 @@ pub trait FileReadRepository: Send + Sync + 'static {
///
/// Covers: upload (buffered + streaming), move, delete, update,
/// and deferred registration for write-behind cache.
#[async_trait]
pub trait FileWriteRepository: Send + Sync + 'static {
/// Saves a new file from bytes.
async fn save_file(
@@ -8,7 +8,6 @@
//! Concrete implementations (filesystem, PostgreSQL, S3, etc.) live in
//! the infrastructure layer.
use async_trait::async_trait;
use crate::common::errors::DomainError;
use crate::domain::entities::folder::Folder;
@@ -18,7 +17,6 @@ use crate::domain::services::path_service::StoragePath;
///
/// Defines the CRUD and management operations required for
/// the Folder entity in the storage system.
#[async_trait]
pub trait FolderRepository: Send + Sync + 'static {
/// Creates a new folder
async fn create_folder(
@@ -1,6 +1,5 @@
use crate::common::errors::DomainError;
use crate::domain::entities::session::Session;
use async_trait::async_trait;
#[derive(Debug, thiserror::Error)]
pub enum SessionRepositoryError {
@@ -29,7 +28,6 @@ impl From<SessionRepositoryError> for DomainError {
}
}
#[async_trait]
pub trait SessionRepository: Send + Sync + 'static {
/// Creates a new session
async fn create_session(&self, session: Session) -> SessionRepositoryResult<Session>;
@@ -1,10 +1,8 @@
use crate::common::errors::DomainError;
use async_trait::async_trait;
use std::collections::HashMap;
/// Repository for platform settings stored in the database.
/// Settings are key-value pairs organized by category (e.g., "oidc", "general").
#[async_trait]
pub trait SettingsRepository: Send + Sync + 'static {
/// Get a single setting value by key
async fn get(&self, key: &str) -> Result<Option<String>, DomainError>;
@@ -1,4 +1,3 @@
use async_trait::async_trait;
use thiserror::Error;
use crate::domain::{
@@ -20,7 +19,6 @@ pub enum ShareRepositoryError {
AlreadyExists(String),
}
#[async_trait]
pub trait ShareRepository: Send + Sync + 'static {
/// Save a new share or update an existing one
async fn save(&self, share: &Share) -> Result<Share, ShareRepositoryError>;
@@ -1,10 +1,8 @@
use async_trait::async_trait;
use uuid::Uuid;
use crate::common::errors::Result;
use crate::domain::entities::trashed_item::TrashedItem;
#[async_trait]
pub trait TrashRepository: Send + Sync {
async fn add_to_trash(&self, item: &TrashedItem) -> Result<()>;
async fn get_trash_items(&self, user_id: &Uuid) -> Result<Vec<TrashedItem>>;
@@ -1,6 +1,5 @@
use crate::common::errors::DomainError;
use crate::domain::entities::user::{User, UserRole};
use async_trait::async_trait;
#[derive(Debug, thiserror::Error)]
pub enum UserRepositoryError {
@@ -41,7 +40,6 @@ impl From<UserRepositoryError> for DomainError {
}
}
#[async_trait]
pub trait UserRepository: Send + Sync + 'static {
/// Creates a new user
async fn create_user(&self, user: User) -> UserRepositoryResult<User>;