From 22043fc95b41262f9771ad6ffccc40a08040a9ec Mon Sep 17 00:00:00 2001 From: Croxx Date: Mon, 9 Sep 2024 18:18:22 +0800 Subject: [PATCH] revert: "perf: introduce size hint for storage ... (#695)" (#696) This reverts commit 260ef1429a658fe8467530f3cd5d7cbae61cd5ee. --- foyer-common/src/code.rs | 18 ++++-------------- foyer-storage/src/serde.rs | 11 ----------- foyer-storage/src/store.rs | 3 +-- 3 files changed, 5 insertions(+), 27 deletions(-) diff --git a/foyer-common/src/code.rs b/foyer-common/src/code.rs index fb47b794..ae4826e6 100644 --- a/foyer-common/src/code.rs +++ b/foyer-common/src/code.rs @@ -25,23 +25,13 @@ impl Key for T {} impl Value for T {} /// Key trait for the disk cache. -pub trait StorageKey: Key + Serialize + DeserializeOwned + Hint {} -impl StorageKey for T where T: Key + Serialize + DeserializeOwned + Hint {} +pub trait StorageKey: Key + Serialize + DeserializeOwned {} +impl StorageKey for T where T: Key + Serialize + DeserializeOwned {} /// Value trait for the disk cache. -pub trait StorageValue: Value + 'static + Serialize + DeserializeOwned + Hint {} -impl StorageValue for T where T: Value + Serialize + DeserializeOwned + Hint {} +pub trait StorageValue: Value + 'static + Serialize + DeserializeOwned {} +impl StorageValue for T where T: Value + Serialize + DeserializeOwned {} /// Hash builder trait. pub trait HashBuilder: BuildHasher + Send + Sync + 'static {} impl HashBuilder for T where T: BuildHasher + Send + Sync + 'static {} - -/// Hint functions collection. -pub trait Hint { - /// Size hint for serialization. - fn serialized_size_hint(&self) -> usize { - 0 - } -} - -impl Hint for T {} diff --git a/foyer-storage/src/serde.rs b/foyer-storage/src/serde.rs index 93a87f38..89642226 100644 --- a/foyer-storage/src/serde.rs +++ b/foyer-storage/src/serde.rs @@ -94,17 +94,6 @@ impl EntrySerializer { Ok(KvInfo { key_len, value_len }) } - - pub fn size_hint<'a, K, V>(key: &'a K, value: &'a V, compression: &'a Compression) -> usize - where - K: StorageKey, - V: StorageValue, - { - match compression { - Compression::Zstd | Compression::Lz4 => 0, - Compression::None => key.serialized_size_hint() + value.serialized_size_hint(), - } - } } #[derive(Debug)] diff --git a/foyer-storage/src/store.rs b/foyer-storage/src/store.rs index 5293e1ad..5c9d804a 100644 --- a/foyer-storage/src/store.rs +++ b/foyer-storage/src/store.rs @@ -144,8 +144,7 @@ where self.inner.write_runtime_handle.spawn(async move { if force || this.pick(entry.key()) { - let mut buffer = - IoBytesMut::with_capacity(EntrySerializer::size_hint(entry.key(), entry.value(), &compression)); + let mut buffer = IoBytesMut::new(); match EntrySerializer::serialize( entry.key(), entry.value(),