feat: Do not clone probably large fst::Sets, Arc them

This commit is contained in:
Clément Renault 2019-08-30 14:37:28 +02:00
parent 3e1b81c4ce
commit ca34c28335
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
5 changed files with 14 additions and 10 deletions

View File

@ -119,8 +119,9 @@ impl<'a> DocumentsAddition<'a> {
main.set_ranked_map(&self.ranked_map)?; main.set_ranked_map(&self.ranked_map)?;
// update the "consistent" view of the Index // update the "consistent" view of the Index
let words = Arc::new(words);
let ranked_map = self.ranked_map; let ranked_map = self.ranked_map;
let synonyms = fst::Set::from_bytes(lease_inner.synonyms.as_fst().to_vec()).unwrap(); // clone() let synonyms = lease_inner.synonyms.clone();
let schema = lease_inner.schema.clone(); let schema = lease_inner.schema.clone();
let raw = lease_inner.raw.clone(); let raw = lease_inner.raw.clone();
lease_inner.raw.compact(); lease_inner.raw.compact();

View File

@ -118,8 +118,9 @@ impl<'a> DocumentsDeletion<'a> {
main.set_ranked_map(&self.ranked_map)?; main.set_ranked_map(&self.ranked_map)?;
// update the "consistent" view of the Index // update the "consistent" view of the Index
let words = Arc::new(words);
let ranked_map = lease_inner.ranked_map.clone(); let ranked_map = lease_inner.ranked_map.clone();
let synonyms = fst::Set::from_bytes(lease_inner.synonyms.as_fst().to_vec()).unwrap(); // clone() let synonyms = lease_inner.synonyms.clone();
let schema = lease_inner.schema.clone(); let schema = lease_inner.schema.clone();
let raw = lease_inner.raw.clone(); let raw = lease_inner.raw.clone();
lease_inner.raw.compact(); lease_inner.raw.compact();

View File

@ -30,8 +30,8 @@ pub struct IndexStats {
pub struct Index(pub ArcSwap<InnerIndex>); pub struct Index(pub ArcSwap<InnerIndex>);
pub struct InnerIndex { pub struct InnerIndex {
pub words: fst::Set, pub words: Arc<fst::Set>,
pub synonyms: fst::Set, pub synonyms: Arc<fst::Set>,
pub schema: Schema, pub schema: Schema,
pub ranked_map: RankedMap, pub ranked_map: RankedMap,
pub raw: RawIndex, // TODO this will be a snapshot in the future pub raw: RawIndex, // TODO this will be a snapshot in the future
@ -40,13 +40,13 @@ pub struct InnerIndex {
impl Index { impl Index {
pub fn from_raw(raw: RawIndex) -> Result<Index, Error> { pub fn from_raw(raw: RawIndex) -> Result<Index, Error> {
let words = match raw.main.words_set()? { let words = match raw.main.words_set()? {
Some(words) => words, Some(words) => Arc::new(words),
None => fst::Set::default(), None => Arc::new(fst::Set::default()),
}; };
let synonyms = match raw.main.synonyms_set()? { let synonyms = match raw.main.synonyms_set()? {
Some(synonyms) => synonyms, Some(synonyms) => Arc::new(synonyms),
None => fst::Set::default(), None => Arc::new(fst::Set::default()),
}; };
let schema = match raw.main.schema()? { let schema = match raw.main.schema()? {

View File

@ -72,8 +72,9 @@ impl<'a> SynonymsAddition<'a> {
main.set_synonyms_set(&synonyms)?; main.set_synonyms_set(&synonyms)?;
// update the "consistent" view of the Index // update the "consistent" view of the Index
let words = main.words_set()?.unwrap_or_default(); let words = Arc::new(main.words_set()?.unwrap_or_default());
let ranked_map = lease_inner.ranked_map.clone(); let ranked_map = lease_inner.ranked_map.clone();
let synonyms = Arc::new(synonyms);
let schema = lease_inner.schema.clone(); let schema = lease_inner.schema.clone();
let raw = lease_inner.raw.clone(); let raw = lease_inner.raw.clone();
lease_inner.raw.compact(); lease_inner.raw.compact();

View File

@ -115,8 +115,9 @@ impl<'a> SynonymsDeletion<'a> {
main.set_synonyms_set(&synonyms)?; main.set_synonyms_set(&synonyms)?;
// update the "consistent" view of the Index // update the "consistent" view of the Index
let words = main.words_set()?.unwrap_or_default(); let words = Arc::new(main.words_set()?.unwrap_or_default());
let ranked_map = lease_inner.ranked_map.clone(); let ranked_map = lease_inner.ranked_map.clone();
let synonyms = Arc::new(synonyms);
let schema = lease_inner.schema.clone(); let schema = lease_inner.schema.clone();
let raw = lease_inner.raw.clone(); let raw = lease_inner.raw.clone();
lease_inner.raw.compact(); lease_inner.raw.compact();