Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert: "perf: introduce size hint for storage ... (#695)" #696

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading