Reuse command lookup hashes and validate cached meanings by shard
This commit is contained in:
1 parent
330c4bde51
commit
d249ec7eba
4 files changed
+105
-30
No files matched your search
@@ -1,9 +1,12 @@
|
||||
use std::collections::{BTreeSet, HashMap, VecDeque};
|
||||
use std::collections::{BTreeSet, VecDeque};
|
||||
use std::hash::{BuildHasher, RandomState};
|
||||
use std::sync::Arc;
|
||||
|
||||
use hashbrown::{HashMap, hash_map::RawEntryMut};
|
||||
|
||||
use super::job::InputStream;
|
||||
use super::mouth::Mouth;
|
||||
use super::state::{GroupKind, Key, Replacement};
|
||||
use super::state::{GroupKind, Key, Replacement, command_hasher};
|
||||
use super::*;
|
||||
mod alignment;
|
||||
mod boxes;
|
||||
@@ -235,8 +238,8 @@ pub struct Executor {
|
||||
generated_inputs: std::collections::BTreeMap<usize, GeneratedInput>,
|
||||
reads: DependencyReads,
|
||||
// Cache the resolved meaning alongside the already required read evidence.
|
||||
// The revision is only valid within this executor and its checkpoints.
|
||||
meaning_reads: HashMap<CommandName, (u64, Meaning)>,
|
||||
// A shard's revision is only valid on this executor's state history.
|
||||
meaning_reads: HashMap<CommandName, (u64, Meaning), RandomState>,
|
||||
reads_tracing_macros: bool,
|
||||
conditionals: Vec<Conditional>,
|
||||
in_csname: bool,
|
||||
@@ -533,7 +536,7 @@ impl Executor {
|
||||
stream_sources: BTreeSet::new(),
|
||||
generated_inputs: Default::default(),
|
||||
reads: DependencyReads::default(),
|
||||
meaning_reads: HashMap::new(),
|
||||
meaning_reads: HashMap::with_hasher(command_hasher().clone()),
|
||||
reads_tracing_macros: false,
|
||||
conditionals: Vec::new(),
|
||||
in_csname: false,
|
||||
@@ -784,17 +787,23 @@ impl Executor {
|
||||
self.lookup_meaning(name)
|
||||
}
|
||||
fn lookup_meaning(&mut self, name: &CommandName) -> Meaning {
|
||||
let revision = self.state.command_revision();
|
||||
if let Some((cached_revision, meaning)) = self.meaning_reads.get_mut(name) {
|
||||
if *cached_revision != revision {
|
||||
*meaning = self.state.meaning(name);
|
||||
*cached_revision = revision;
|
||||
let hash = self.meaning_reads.hasher().hash_one(name);
|
||||
let revision = self.state.command_revision(hash);
|
||||
match self.meaning_reads.raw_entry_mut().from_key_hashed_nocheck(hash, name) {
|
||||
RawEntryMut::Occupied(mut entry) => {
|
||||
let (cached_revision, meaning) = entry.get_mut();
|
||||
if *cached_revision != revision {
|
||||
*meaning = self.state.meaning_hashed(name, hash);
|
||||
*cached_revision = revision;
|
||||
}
|
||||
meaning.clone()
|
||||
}
|
||||
RawEntryMut::Vacant(entry) => {
|
||||
let meaning = self.state.meaning_hashed(name, hash);
|
||||
entry.insert_hashed_nocheck(hash, name.clone(), (revision, meaning.clone()));
|
||||
meaning
|
||||
}
|
||||
return meaning.clone();
|
||||
}
|
||||
let meaning = self.state.meaning(name);
|
||||
self.meaning_reads.insert(name.clone(), (revision, meaning.clone()));
|
||||
meaning
|
||||
}
|
||||
fn primitive(&mut self, token: &Token) -> Option<Primitive> {
|
||||
match self.meaning(token) {
|
||||
|
||||
Reference in new issue
Block a user