perf: separate Clone implementation for Draft struct and remove trait bound from struct definition

Improve around 2% - 16% CPU performance
This commit is contained in:
Tunglies 2026-01-28 10:28:26 +08:00
parent c57a962109
commit 5103868119
No known key found for this signature in database
GPG Key ID: B9B01B389469B3E8

View File

@ -6,8 +6,8 @@ type DraftInner<T> = (SharedDraft<T>, Option<SharedDraft<T>>);
/// Draft 管理committed 与 optional draft 都以 Arc<Box<T>> 存储,
// (committed_snapshot, optional_draft_snapshot)
#[derive(Debug, Clone)]
pub struct Draft<T: Clone> {
#[derive(Debug)]
pub struct Draft<T> {
inner: Arc<RwLock<DraftInner<T>>>,
}
@ -90,3 +90,11 @@ impl<T: Clone> Draft<T> {
Ok(res)
}
}
impl<T: Clone> Clone for Draft<T> {
fn clone(&self) -> Self {
Self {
inner: Arc::clone(&self.inner),
}
}
}