From 12534e55a341b82e5c27973df9b02656ab9ba097 Mon Sep 17 00:00:00 2001 From: Paul Masurel Date: Wed, 3 Aug 2016 11:13:35 +0900 Subject: [PATCH 1/2] Lighter HeapItem by putting term freq aside, and keeping ord as u32 --- src/postings/union_postings.rs | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/postings/union_postings.rs b/src/postings/union_postings.rs index 2182933b9..a5c4e02a9 100644 --- a/src/postings/union_postings.rs +++ b/src/postings/union_postings.rs @@ -6,18 +6,17 @@ use query::MultiTermScorer; use postings::ScoredDocSet; use query::Scorer; use fastfield::U32FastFieldReader; - +use std::iter; #[derive(Eq, PartialEq)] -struct HeapItem(DocId, usize, u32); +struct HeapItem(DocId, u32); impl HeapItem { pub fn ord(&self,) -> usize{ - self.1 + self.1 as usize } } - impl PartialOrd for HeapItem { fn partial_cmp(&self, other:&Self) -> Option { Some(self.cmp(&other)) @@ -26,13 +25,14 @@ impl PartialOrd for HeapItem { impl Ord for HeapItem { fn cmp(&self, other:&Self) -> Ordering { - (self.0, self.1).cmp(&(other.0, other.1)).reverse() + (other.0).cmp(&self.0) } } pub struct UnionPostings { fieldnorms_readers: Vec, postings: Vec, + term_frequencies: Vec, queue: BinaryHeap, doc: DocId, scorer: MultiTermScorer @@ -43,23 +43,27 @@ impl UnionPostings { pub fn new(fieldnorms_reader: Vec, mut postings: Vec, multi_term_scorer: MultiTermScorer) -> UnionPostings { let num_postings = postings.len(); assert_eq!(fieldnorms_reader.len(), num_postings); - + for posting in &mut postings { assert!(posting.next()); } - let heap_items: Vec = postings.iter() + let mut term_frequencies: Vec = iter::repeat(0u32).take(num_postings).collect(); + let heap_items: Vec = postings + .iter() .map(|posting| { (posting.doc(), posting.term_freq()) }) .enumerate() .map(|(ord, (doc, tf))| { - HeapItem(doc, ord, tf) + term_frequencies[ord] = tf; + HeapItem(doc, ord as u32) }) .collect(); UnionPostings { fieldnorms_readers: fieldnorms_reader, postings: postings, + term_frequencies: term_frequencies, queue: BinaryHeap::from(heap_items), doc: 0, scorer: multi_term_scorer @@ -71,13 +75,12 @@ impl UnionPostings { let cur_postings = &mut self.postings[ord]; if cur_postings.next() { let doc = cur_postings.doc(); - let tf = cur_postings.term_freq(); - self.queue.replace(HeapItem(doc, ord, tf)); + self.term_frequencies[ord] = cur_postings.term_freq(); + self.queue.replace(HeapItem(doc, ord as u32)); } else { self.queue.pop(); } - } fn get_field_norm(&self, ord:usize, doc:DocId) -> u32 { @@ -93,9 +96,11 @@ impl DocSet for UnionPostings { self.scorer.clear(); let cur_doc: DocId; match self.queue.peek() { - Some(&HeapItem(doc, ord, tf)) => { + Some(&HeapItem(doc, ord)) => { cur_doc = doc; + let ord: usize = ord as usize; let fieldnorm = self.get_field_norm(ord, doc); + let tf = self.term_frequencies[ord]; self.scorer.update(ord, tf, fieldnorm); } @@ -106,11 +111,13 @@ impl DocSet for UnionPostings { self.advance_head(); loop { match self.queue.peek() { - Some(&HeapItem(peek_doc, peek_ord, peek_tf)) => { + Some(&HeapItem(peek_doc, peek_ord)) => { if peek_doc != cur_doc { break; } else { + let peek_ord: usize = peek_ord as usize; + let peek_tf = self.term_frequencies[peek_ord]; let fieldnorm = self.get_field_norm(peek_ord, peek_doc); self.scorer.update(peek_ord, peek_tf, fieldnorm); } From 44f3f23d481bc88f1f9398b714eb87e34b9fc33d Mon Sep 17 00:00:00 2001 From: Paul Masurel Date: Wed, 3 Aug 2016 15:42:10 +0900 Subject: [PATCH 2/2] Changed block size to 16K --- src/store/writer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/store/writer.rs b/src/store/writer.rs index 5a968c2bd..281393c7b 100644 --- a/src/store/writer.rs +++ b/src/store/writer.rs @@ -9,7 +9,7 @@ use lz4; use super::StoreReader; use super::OffsetIndex; -const BLOCK_SIZE: usize = 131_072; +const BLOCK_SIZE: usize = 16_384; pub struct StoreWriter { doc: DocId,