Skip to content

Commit

Permalink
revert: "perf: introduce size hint for storage ... (#695)" (#696)
Browse files Browse the repository at this point in the history
This reverts commit 260ef14.
  • Loading branch information
MrCroxx authored Sep 9, 2024
1 parent 260ef14 commit 22043fc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 27 deletions.
18 changes: 4 additions & 14 deletions foyer-common/src/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,13 @@ impl<T: Send + Sync + 'static + std::hash::Hash + Eq> Key for T {}
impl<T: Send + Sync + 'static> Value for T {}

/// Key trait for the disk cache.
pub trait StorageKey: Key + Serialize + DeserializeOwned + Hint {}
impl<T> StorageKey for T where T: Key + Serialize + DeserializeOwned + Hint {}
pub trait StorageKey: Key + Serialize + DeserializeOwned {}
impl<T> StorageKey for T where T: Key + Serialize + DeserializeOwned {}

/// Value trait for the disk cache.
pub trait StorageValue: Value + 'static + Serialize + DeserializeOwned + Hint {}
impl<T> StorageValue for T where T: Value + Serialize + DeserializeOwned + Hint {}
pub trait StorageValue: Value + 'static + Serialize + DeserializeOwned {}
impl<T> StorageValue for T where T: Value + Serialize + DeserializeOwned {}

/// Hash builder trait.
pub trait HashBuilder: BuildHasher + Send + Sync + 'static {}
impl<T> 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<T: Send + Sync + 'static> Hint for T {}
11 changes: 0 additions & 11 deletions foyer-storage/src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
3 changes: 1 addition & 2 deletions foyer-storage/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 22043fc

Please sign in to comment.