Commit 439f2abe authored by Luke Sandberg's avatar Luke Sandberg

use a different configuration for hashing, no varints

parent 444a4263
......@@ -14,6 +14,13 @@ use bincode::{
use turbo_tasks_hash::DeterministicHasher;
pub const TURBO_BINCODE_CONFIG: bincode::config::Configuration = bincode::config::standard();
/// Same as standard config, but since we aren't encoding we don't benefit from varint
/// optimizations.
pub const TURBO_BINCODE_HASH_CONFIG: bincode::config::Configuration<
bincode::config::LittleEndian,
bincode::config::Fixint,
bincode::config::NoLimit,
> = TURBO_BINCODE_CONFIG.with_fixed_int_encoding();
pub type TurboBincodeBuffer = SmallVec<[u8; 16]>;
pub type TurboBincodeEncoder<'a> =
EncoderImpl<TurboBincodeWriter<'a>, bincode::config::Configuration>;
......@@ -144,13 +151,20 @@ impl<H: DeterministicHasher + ?Sized> Writer for HashWriter<'_, H> {
}
/// An encoder that writes directly to a [`DeterministicHasher`].
pub type HashEncoder<'a, H> = EncoderImpl<HashWriter<'a, H>, bincode::config::Configuration>;
pub type HashEncoder<'a, H> = EncoderImpl<
HashWriter<'a, H>,
bincode::config::Configuration<
bincode::config::LittleEndian,
bincode::config::Fixint,
bincode::config::NoLimit,
>,
>;
/// Creates a new [`HashEncoder`] that encodes directly to the given hasher.
///
/// This is useful for computing hashes of encoded values without allocating a buffer.
pub fn new_hash_encoder<H: DeterministicHasher + ?Sized>(hasher: &mut H) -> HashEncoder<'_, H> {
EncoderImpl::new(HashWriter::new(hasher), TURBO_BINCODE_CONFIG)
EncoderImpl::new(HashWriter::new(hasher), TURBO_BINCODE_HASH_CONFIG)
}
/// Represents a type that can only be encoded with a [`TurboBincodeEncoder`].
......
......@@ -374,7 +374,6 @@ impl<T: KeyValueDatabase + Send + Sync + 'static> BackingStorageSealed
items = task_cache_updates.iter().map(|m| m.len()).sum::<usize>()
)
.entered();
for (task_type, task_id) in task_cache_updates.into_iter().flatten() {
let hash = compute_task_type_hash(&task_type);
let task_id = *task_id;
......@@ -423,15 +422,15 @@ impl<T: KeyValueDatabase + Send + Sync + 'static> BackingStorageSealed
task_type: &CachedTaskType,
) -> Result<SmallVec<[TaskId; 1]>> {
let hash = compute_task_type_hash(task_type);
let results = database.get_multiple(tx, KeySpace::TaskCache, &hash.to_le_bytes())?;
let buffers = database.get_multiple(tx, KeySpace::TaskCache, &hash.to_le_bytes())?;
Ok(results
.iter()
.map(|bytes| {
let as_array = bytes.borrow().try_into().unwrap();
TaskId::try_from(u32::from_le_bytes(as_array)).unwrap()
})
.collect())
let mut task_ids = SmallVec::with_capacity(buffers.len());
for bytes in buffers {
let bytes = bytes.borrow().try_into()?;
let id = TaskId::try_from(u32::from_le_bytes(bytes)).unwrap();
task_ids.push(id);
}
Ok(task_ids)
}
if inner.database.is_empty() {
// Checking if the database is empty is a performance optimization
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment