Use the new Lru

This commit is contained in:
Clément Renault 2024-09-25 14:54:56 +02:00
parent 759b9b1546
commit 86d5e6d9ff
No known key found for this signature in database
GPG Key ID: F250A4C4E3AE5F5F
7 changed files with 11 additions and 42 deletions

10
Cargo.lock generated
View File

@ -3312,15 +3312,6 @@ version = "0.4.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c"
[[package]]
name = "lru"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37ee39891760e7d94734f6f63fedc29a2e4a152f836120753a72503f09fcf904"
dependencies = [
"hashbrown 0.14.5",
]
[[package]] [[package]]
name = "lzma-rs" name = "lzma-rs"
version = "0.3.0" version = "0.3.0"
@ -3584,7 +3575,6 @@ dependencies = [
"json-depth-checker", "json-depth-checker",
"levenshtein_automata", "levenshtein_automata",
"liquid", "liquid",
"lru",
"maplit", "maplit",
"md5", "md5",
"meili-snap", "meili-snap",

View File

@ -44,26 +44,5 @@ opt-level = 3
[profile.dev.package.roaring] [profile.dev.package.roaring]
opt-level = 3 opt-level = 3
[profile.dev.package.lindera-ipadic-builder]
opt-level = 3
[profile.dev.package.encoding]
opt-level = 3
[profile.dev.package.yada]
opt-level = 3
[profile.release.package.lindera-ipadic-builder]
opt-level = 3
[profile.release.package.encoding]
opt-level = 3
[profile.release.package.yada]
opt-level = 3
[profile.bench.package.lindera-ipadic-builder]
opt-level = 3
[profile.bench.package.encoding]
opt-level = 3
[profile.bench.package.yada]
opt-level = 3
[patch.crates-io] [patch.crates-io]
roaring = { git = "https://github.com/RoaringBitmap/roaring-rs", branch = "clone-iter-slice" } roaring = { git = "https://github.com/RoaringBitmap/roaring-rs", branch = "clone-iter-slice" }

View File

@ -40,7 +40,6 @@ heed = { version = "0.20.3", default-features = false, features = [
indexmap = { version = "2.2.6", features = ["serde"] } indexmap = { version = "2.2.6", features = ["serde"] }
json-depth-checker = { path = "../json-depth-checker" } json-depth-checker = { path = "../json-depth-checker" }
levenshtein_automata = { version = "0.2.1", features = ["fst_automaton"] } levenshtein_automata = { version = "0.2.1", features = ["fst_automaton"] }
lru = "0.12.3"
memchr = "2.5.0" memchr = "2.5.0"
memmap2 = "0.9.4" memmap2 = "0.9.4"
obkv = { git = "https://github.com/kerollmops/obkv", branch = "unsized-kvreader" } obkv = { git = "https://github.com/kerollmops/obkv", branch = "unsized-kvreader" }

View File

@ -2,16 +2,16 @@ use std::mem;
use std::num::NonZeroUsize; use std::num::NonZeroUsize;
use grenad::{MergeFunction, Sorter}; use grenad::{MergeFunction, Sorter};
use lru::LruCache;
use roaring::RoaringBitmap; use roaring::RoaringBitmap;
use smallvec::SmallVec; use smallvec::SmallVec;
use super::lru::Lru;
use crate::update::del_add::{DelAdd, KvWriterDelAdd}; use crate::update::del_add::{DelAdd, KvWriterDelAdd};
use crate::CboRoaringBitmapCodec; use crate::CboRoaringBitmapCodec;
#[derive(Debug)] #[derive(Debug)]
pub struct CboCachedSorter<MF> { pub struct CboCachedSorter<MF> {
cache: lru::LruCache<SmallVec<[u8; 20]>, DelAddRoaringBitmap>, cache: Lru<SmallVec<[u8; 20]>, DelAddRoaringBitmap>,
sorter: Sorter<MF>, sorter: Sorter<MF>,
deladd_buffer: Vec<u8>, deladd_buffer: Vec<u8>,
cbo_buffer: Vec<u8>, cbo_buffer: Vec<u8>,
@ -22,7 +22,7 @@ pub struct CboCachedSorter<MF> {
impl<MF> CboCachedSorter<MF> { impl<MF> CboCachedSorter<MF> {
pub fn new(cap: NonZeroUsize, sorter: Sorter<MF>) -> Self { pub fn new(cap: NonZeroUsize, sorter: Sorter<MF>) -> Self {
CboCachedSorter { CboCachedSorter {
cache: lru::LruCache::new(cap), cache: Lru::new(cap),
sorter, sorter,
deladd_buffer: Vec::new(), deladd_buffer: Vec::new(),
cbo_buffer: Vec::new(), cbo_buffer: Vec::new(),
@ -171,7 +171,7 @@ impl<MF: MergeFunction> CboCachedSorter<MF> {
} }
pub fn into_sorter(mut self) -> grenad::Result<Sorter<MF>, MF::Error> { pub fn into_sorter(mut self) -> grenad::Result<Sorter<MF>, MF::Error> {
let default_arc = LruCache::new(NonZeroUsize::MIN); let default_arc = Lru::new(NonZeroUsize::MIN);
for (key, deladd) in mem::replace(&mut self.cache, default_arc) { for (key, deladd) in mem::replace(&mut self.cache, default_arc) {
self.write_entry(key, deladd)?; self.write_entry(key, deladd)?;
} }

View File

@ -7,6 +7,7 @@ use std::num::NonZeroUsize;
use hashbrown::hash_map::{DefaultHashBuilder, Entry}; use hashbrown::hash_map::{DefaultHashBuilder, Entry};
use hashbrown::HashMap; use hashbrown::HashMap;
#[derive(Debug)]
pub struct Lru<K, V, S = DefaultHashBuilder> { pub struct Lru<K, V, S = DefaultHashBuilder> {
lookup: HashMap<K, usize, S>, lookup: HashMap<K, usize, S>,
storage: FixedSizeList<LruNode<K, V>>, storage: FixedSizeList<LruNode<K, V>>,
@ -104,17 +105,20 @@ impl<K, V> Iterator for IntoIter<K, V> {
} }
} }
#[derive(Debug)]
struct LruNode<K, V> { struct LruNode<K, V> {
key: K, key: K,
value: V, value: V,
} }
#[derive(Debug)]
struct FixedSizeListNode<T> { struct FixedSizeListNode<T> {
prev: usize, prev: usize,
next: usize, next: usize,
data: T, data: T,
} }
#[derive(Debug)]
struct FixedSizeList<T> { struct FixedSizeList<T> {
nodes: Box<[Option<FixedSizeListNode<T>>]>, nodes: Box<[Option<FixedSizeListNode<T>>]>,
// An un-ordered set of indices that are not in use in `nodes`. // An un-ordered set of indices that are not in use in `nodes`.

View File

@ -1,5 +1,6 @@
mod cache; mod cache;
mod faceted; mod faceted;
mod lru;
mod searchable; mod searchable;
use std::fs::File; use std::fs::File;
@ -9,12 +10,9 @@ use grenad::Merger;
use rayon::iter::IntoParallelIterator; use rayon::iter::IntoParallelIterator;
pub use searchable::*; pub use searchable::*;
use crate::{
update::{GrenadParameters, MergeDeladdCboRoaringBitmaps},
GlobalFieldsIdsMap, Index, Result,
};
use super::DocumentChange; use super::DocumentChange;
use crate::update::{GrenadParameters, MergeDeladdCboRoaringBitmaps};
use crate::{GlobalFieldsIdsMap, Index, Result};
pub trait DocidsExtractor { pub trait DocidsExtractor {
fn run_extraction( fn run_extraction(

View File

@ -10,7 +10,6 @@ mod document_change;
mod extract; mod extract;
pub mod indexer; pub mod indexer;
mod items_pool; mod items_pool;
mod lru;
mod merger; mod merger;
mod top_level_map; mod top_level_map;
mod word_fst_builder; mod word_fst_builder;