From daffcaf4c63d55722286ea84dbca946c5ae98946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Sun, 19 Jan 2020 12:11:59 +0100 Subject: [PATCH] Make the docids OR operation method conditional --- meilisearch-core/src/query_tree.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/meilisearch-core/src/query_tree.rs b/meilisearch-core/src/query_tree.rs index 2694e47ac..7b353e81c 100644 --- a/meilisearch-core/src/query_tree.rs +++ b/meilisearch-core/src/query_tree.rs @@ -442,8 +442,17 @@ pub fn traverse_query_tree<'o, 'txn>( println!("{:3$}docids retrieval ({:?}) took {:.02?}", "", results.len(), before.elapsed(), depth * 2); let before = Instant::now(); - let sets = results.iter().map(AsRef::as_ref).collect(); - let docids = sdset::multi::Union::new(sets).into_set_buf(); + let docids = if results.len() > 10 { + let cap = results.iter().map(|dis| dis.len()).sum(); + let mut docids = Vec::with_capacity(cap); + for dis in results { + docids.extend_from_slice(&dis); + } + SetBuf::from_dirty(docids) + } else { + let sets = results.iter().map(AsRef::as_ref).collect(); + sdset::multi::Union::new(sets).into_set_buf() + }; println!("{:2$}docids construction took {:.02?}", "", before.elapsed(), depth * 2); Cow::Owned(docids) @@ -473,8 +482,17 @@ pub fn traverse_query_tree<'o, 'txn>( println!("{:3$}docids retrieval ({:?}) took {:.02?}", "", results.len(), before.elapsed(), depth * 2); let before = Instant::now(); - let sets = results.iter().map(AsRef::as_ref).collect(); - let docids = sdset::multi::Union::new(sets).into_set_buf(); + let docids = if results.len() > 10 { + let cap = results.iter().map(|dis| dis.len()).sum(); + let mut docids = Vec::with_capacity(cap); + for dis in results { + docids.extend_from_slice(&dis); + } + SetBuf::from_dirty(docids) + } else { + let sets = results.iter().map(AsRef::as_ref).collect(); + sdset::multi::Union::new(sets).into_set_buf() + }; println!("{:2$}docids construction took {:.02?}", "", before.elapsed(), depth * 2); Cow::Owned(docids)