Skip to content
Merged
1 change: 1 addition & 0 deletions crates/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/vector-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ ghash = "0.6"
argon2 = "0.5.3"
sha2 = "0.10.9"
unicode-normalization = "0.1"
memchr = "2"
# HKDF-SHA256 for the Community protocol's frozen key-derivation convention
# (GROUP_PROTOCOL.md §14). Audited RustCrypto crate rather than a hand-rolled
# construction, since the derivation is wire-immutable.
Expand Down
2 changes: 2 additions & 0 deletions crates/vector-core/benches/core/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod compact;
mod db_reads;
mod parse;
mod pool;
mod search;

use nostr_sdk::prelude::{Keys, ToBech32};
use vector_core::crypto::guarded_key::bench as vault;
Expand All @@ -38,6 +39,7 @@ const ALL: &[(&str, fn())] = &[
("crypto::chacha20_raw", parse::chacha20_raw),
("crypto::nip44_decrypt", parse::nip44_decrypt),
("crypto::chacha20_backends", parse::chacha20_backends),
("search::scan", search::scan),
("profile::processor", vector_core::profile::sync::bench::processor),
("vault::designs", vault::designs),
("vault::set_sources", vault::set_sources),
Expand Down
64 changes: 64 additions & 0 deletions crates/vector-core/benches/core/search.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//! Message search: building the corpus, then the scans a keystroke runs.

use std::time::Instant;
use vector_core::search::{Corpus, Filter, Has, Query, Record};

const WORDS: &[&str] = &[
"the", "build", "relay", "lunch", "tomorrow", "café", "release", "voice", "channel", "bug",
"fixed", "photo", "meeting", "deploy", "東京", "会議", "night", "cats", "music", "invoice",
];

/// 200,000 messages of 12 to 30 words across 300 chats.
pub fn scan() {
const N: usize = 200_000;
let mut seed = 0x9e37_79b9_7f4a_7c15u64;
let mut next = || {
seed ^= seed << 13;
seed ^= seed >> 7;
seed ^= seed << 17;
seed
};
let records: Vec<Record> = (0..N)
.map(|i| {
let n = 12 + (next() % 19) as usize;
let text = (0..n).map(|_| WORDS[(next() % WORDS.len() as u64) as usize]).collect::<Vec<_>>().join(" ");
let files = if i % 25 == 0 { vec![("jpg".to_string(), format!("IMG_{i}.jpg"))] } else { Vec::new() };
Record {
chat: format!("chat{}", next() % 300),
id: format!("{i:064x}"),
author: Some(format!("npub1{:0>58}", next() % 500)),
mine: i % 7 == 0,
at: 1_800_000_000_000 - i as u64 * 1000,
text,
files,
}
})
.collect();
let t = Instant::now();
let mut corpus = Corpus::new();
for r in &records {
corpus.push(r, &r.text);
}
println!("build {:>9.1} ms ({} messages)", t.elapsed().as_secs_f64() * 1e3, corpus.len());

let cases: &[(&str, &str, Filter)] = &[
("rare word", "invoice deploy", Filter::default()),
("common word", "the", Filter::default()),
("no match", "zzzzzz", Filter::default()),
("cjk", "会議", Filter::default()),
("phrase", "\"lunch tomorrow\"", Filter::default()),
("has:image", "", Filter { has: Has::IMAGE, ..Default::default() }),
("in: + word", "relay", Filter { chats: vec!["chat7".into()], ..Default::default() }),
("oldest", "cats", Filter { oldest: true, ..Default::default() }),
];
for (name, q, f) in cases {
let query = Query::parse(q);
let runs = 20;
let t = Instant::now();
let mut total = 0;
for _ in 0..runs {
total = corpus.search(&query, f, 200).total;
}
println!("{name:<12} {:>7.2} ms ({total} matches)", t.elapsed().as_secs_f64() * 1e3 / runs as f64);
}
}
1 change: 1 addition & 0 deletions crates/vector-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ pub mod requests;

// === Message Deletion (NIP-09 against retained gift-wraps) ===
pub mod deletion;
pub mod search;
pub mod early;
pub mod self_destruct;
pub mod transfer;
Expand Down
Loading
Loading