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
@@ -18,6 +18,10 @@ use crate::application::ports::auth_ports::{
use crate::common::errors::{DomainError, ErrorKind};
use crate::domain::entities::device_code::{DeviceCode, DeviceCodeStatus};
use crate::domain::entities::session::Session;
use crate::infrastructure::repositories::pg::DeviceCodePgRepository;
use crate::infrastructure::services::jwt_service::JwtTokenService;
use crate::infrastructure::repositories::pg::SessionPgRepository;
use crate::infrastructure::repositories::pg::UserPgRepository;
/// Default device code lifetime: 15 minutes (RFC 8628 recommends 5-30 min).
const DEVICE_CODE_LIFETIME_SECS: i64 = 900;
@@ -34,20 +38,20 @@ const USER_CODE_LETTER_LEN: usize = 4;
const USER_CODE_DIGIT_LEN: usize = 4;
pub struct DeviceAuthService {
device_code_storage: Arc<dyn DeviceCodeStoragePort>,
token_service: Arc<dyn TokenServicePort>,
user_storage: Arc<dyn UserStoragePort>,
session_storage: Arc<dyn SessionStoragePort>,
device_code_storage: Arc<DeviceCodePgRepository>,
token_service: Arc<JwtTokenService>,
user_storage: Arc<UserPgRepository>,
session_storage: Arc<SessionPgRepository>,
/// Base URL of the server (e.g. "https://cloud.example.com")
base_url: String,
}
impl DeviceAuthService {
pub fn new(
device_code_storage: Arc<dyn DeviceCodeStoragePort>,
token_service: Arc<dyn TokenServicePort>,
user_storage: Arc<dyn UserStoragePort>,
session_storage: Arc<dyn SessionStoragePort>,
device_code_storage: Arc<DeviceCodePgRepository>,
token_service: Arc<JwtTokenService>,
user_storage: Arc<UserPgRepository>,
session_storage: Arc<SessionPgRepository>,
base_url: String,
) -> Self {
Self {