Skip to content

Commit d8caf55

Browse files
authored
Merge pull request #130 from meilisearch/remove-sync-point
Parallelize arroy again*
2 parents 693f77d + e0d18a0 commit d8caf55

18 files changed

+2095
-733
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ thiserror = "2.0.9"
2828
nohash = "0.2.0"
2929
page_size = "0.6.0"
3030
enum-iterator = "2.1.0"
31+
thread_local = "1.1.8"
32+
crossbeam = "0.8.4"
3133

3234
[dev-dependencies]
3335
anyhow = "1.0.95"

src/distance/cosine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub enum Cosine {}
2020
#[repr(C)]
2121
#[derive(Pod, Zeroable, Clone, Copy)]
2222
pub struct NodeHeaderCosine {
23-
norm: f32,
23+
pub(crate) norm: f32,
2424
}
2525
impl fmt::Debug for NodeHeaderCosine {
2626
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

src/distance/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ pub trait Distance: Send + Sync + Sized + Clone + fmt::Debug + 'static {
117117
) -> heed::Result<()> {
118118
Ok(())
119119
}
120+
121+
fn size_of_item(dimensions: usize) -> usize {
122+
std::mem::size_of::<Self::Header>() + Self::VectorCodec::size_of_item(dimensions)
123+
}
120124
}
121125

122126
fn two_means<D: Distance, R: Rng>(

src/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl<'a> heed::BytesEncode<'a> for MetadataCodec {
2323

2424
fn bytes_encode(item: &'a Self::EItem) -> Result<Cow<'a, [u8]>, BoxedError> {
2525
let Metadata { dimensions, items, roots, distance } = item;
26-
debug_assert!(!distance.as_bytes().iter().any(|&b| b == 0));
26+
debug_assert!(!distance.as_bytes().contains(&0));
2727

2828
let mut output = Vec::with_capacity(
2929
size_of::<u32>()

src/node.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ pub enum Node<'a, D: Distance> {
1919
SplitPlaneNormal(SplitPlaneNormal<'a, D>),
2020
}
2121

22+
impl<'a, D: Distance> Node<'a, D> {
23+
pub fn into_owned(self) -> Node<'static, D> {
24+
match self {
25+
Node::Leaf(leaf) => Node::Leaf(leaf.into_owned()),
26+
Node::Descendants(descendants) => Node::Descendants(Descendants {
27+
descendants: Cow::Owned(descendants.descendants.into_owned()),
28+
}),
29+
Node::SplitPlaneNormal(split_plane_normal) => {
30+
Node::SplitPlaneNormal(split_plane_normal.into_owned())
31+
}
32+
}
33+
}
34+
}
35+
2236
/// A node generic over the version of the database.
2337
/// Should only be used while reading from the database.
2438
#[derive(Clone, Debug)]
@@ -40,8 +54,15 @@ impl<'a, D: Distance> Node<'a, D> {
4054
None
4155
}
4256
}
43-
}
4457

58+
pub fn descendants(self) -> Option<Descendants<'a>> {
59+
if let Node::Descendants(descendants) = self {
60+
Some(descendants)
61+
} else {
62+
None
63+
}
64+
}
65+
}
4566
/// A leaf node which corresponds to the vector inputed
4667
/// by the user and the distance header.
4768
pub struct Leaf<'a, D: Distance> {
@@ -142,6 +163,19 @@ impl<D: Distance> fmt::Debug for SplitPlaneNormal<'_, D> {
142163
}
143164
}
144165

166+
impl<D: Distance> SplitPlaneNormal<'_, D> {
167+
pub fn into_owned(self) -> SplitPlaneNormal<'static, D> {
168+
SplitPlaneNormal {
169+
left: self.left,
170+
right: self.right,
171+
normal: self.normal.map(|normal| Leaf {
172+
header: normal.header,
173+
vector: Cow::Owned(normal.vector.into_owned()),
174+
}),
175+
}
176+
}
177+
}
178+
145179
impl<D: Distance> Clone for SplitPlaneNormal<'_, D> {
146180
fn clone(&self) -> Self {
147181
Self { left: self.left, right: self.right, normal: self.normal.clone() }

0 commit comments

Comments
 (0)