commit 7f6dd15f769d6d64b69583e45fffd8e2fd95cedd
parent f981dc10479940759d48ff3806a460464981e09d
Author: William Casarin <jb55@jb55.com>
Date: Mon, 5 Jan 2026 12:06:35 -0800
perf: profile a few more things
to debug the messages perf issue
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
5 files changed, 37 insertions(+), 21 deletions(-)
diff --git a/crates/notedeck/src/app.rs b/crates/notedeck/src/app.rs
@@ -428,6 +428,7 @@ pub fn install_crypto() {
let _ = provider.install_default();
}
+#[profiling::function]
pub fn try_process_events_core(
app_ctx: &mut AppContext<'_>,
ctx: &egui::Context,
@@ -443,7 +444,6 @@ pub fn try_process_events_core(
// NOTE: we don't use the while let loop due to borrow issues
#[allow(clippy::while_let_loop)]
loop {
- profiling::scope!("receiving events");
let ev = if let Some(ev) = app_ctx.pool.try_recv() {
ev.into_owned()
} else {
@@ -475,6 +475,7 @@ pub fn try_process_events_core(
}
}
+#[profiling::function]
fn process_message_core(ctx: &mut AppContext<'_>, relay: &str, msg: &RelayMessage) {
match msg {
RelayMessage::Event(_subid, ev) => {
diff --git a/crates/notedeck_columns/src/timeline/mod.rs b/crates/notedeck_columns/src/timeline/mod.rs
@@ -354,6 +354,7 @@ impl Timeline {
/// Initial insert of notes into a timeline. Subsequent inserts should
/// just use the insert function
+ #[profiling::function]
pub fn insert_new(
&mut self,
txn: &Transaction,
@@ -588,6 +589,7 @@ pub fn setup_new_timeline(
/// when we first connect to a new relay for the first time. For
/// situations where you are adding a new timeline, use
/// setup_new_timeline.
+#[profiling::function]
pub fn send_initial_timeline_filters(
since_optimize: bool,
timeline_cache: &mut TimelineCache,
@@ -702,6 +704,7 @@ pub fn fetch_contact_list(subs: &mut Subscriptions, timeline: &mut Timeline, acc
subs.subs.insert(sub.remote.clone(), sub_kind);
}
+#[profiling::function]
fn setup_initial_timeline(
ndb: &Ndb,
txn: &Transaction,
@@ -754,6 +757,7 @@ fn setup_initial_timeline(
Ok(())
}
+#[profiling::function]
pub fn setup_initial_nostrdb_subs(
ndb: &Ndb,
note_cache: &mut NoteCache,
diff --git a/crates/notedeck_messages/src/cache/conversation.rs b/crates/notedeck_messages/src/cache/conversation.rs
@@ -71,29 +71,33 @@ impl ConversationCache {
// We should try and get more messages... this isn't ideal
let chatroom_filter = chatroom_filter(participants, selected);
- let results = match ndb.query(txn, &chatroom_filter, 500) {
- Ok(r) => r,
- Err(e) => {
- tracing::error!("problem with chatroom filter ndb::query: {e:?}");
- return;
- }
- };
let mut updated = false;
- for res in results {
- let participants = get_participants(&res.note);
- let parts = ParticipantSetUnowned::new(participants);
- let cur_id = self
- .registry
- .get_or_insert(ConversationIdentifierUnowned::Nip17(parts));
-
- if cur_id != id {
- // this note isn't relevant to the current conversation, unfortunately...
- continue;
+ {
+ profiling::scope!("chatroom_filter");
+ let results = match ndb.query(txn, &chatroom_filter, 500) {
+ Ok(r) => r,
+ Err(e) => {
+ tracing::error!("problem with chatroom filter ndb::query: {e:?}");
+ return;
+ }
+ };
+
+ for res in results {
+ let participants = get_participants(&res.note);
+ let parts = ParticipantSetUnowned::new(participants);
+ let cur_id = self
+ .registry
+ .get_or_insert(ConversationIdentifierUnowned::Nip17(parts));
+
+ if cur_id != id {
+ // this note isn't relevant to the current conversation, unfortunately...
+ continue;
+ }
+
+ UnknownIds::update_from_note(txn, ndb, unknown_ids, note_cache, &res.note);
+ updated |= conversation.ingest_kind_14(res.note, res.note_key);
}
-
- UnknownIds::update_from_note(txn, ndb, unknown_ids, note_cache, &res.note);
- updated |= conversation.ingest_kind_14(res.note, res.note_key);
}
if updated {
@@ -105,6 +109,7 @@ impl ConversationCache {
tracing::info!("Set active to {id}");
}
+ #[profiling::function]
pub fn init_conversations(
&mut self,
ndb: &Ndb,
@@ -125,6 +130,7 @@ impl ConversationCache {
}
}
+ #[profiling::function]
pub fn ingest_chatroom_msg(
&mut self,
note: Note,
@@ -309,6 +315,7 @@ impl Default for ConversationCache {
}
}
+#[profiling::function]
fn get_conversations<'a>(
ndb: &Ndb,
txn: &'a Transaction,
diff --git a/crates/notedeck_messages/src/lib.rs b/crates/notedeck_messages/src/lib.rs
@@ -41,6 +41,7 @@ impl Default for MessagesApp {
}
impl App for MessagesApp {
+ #[profiling::function]
fn update(&mut self, ctx: &mut AppContext<'_>, ui: &mut egui::Ui) -> AppResponse {
try_process_events_core(ctx, ui.ctx(), |_, _| {});
@@ -113,6 +114,7 @@ impl App for MessagesApp {
}
}
+#[profiling::function]
fn initialize(ctx: &mut AppContext, cache: &mut ConversationCache, is_narrow: bool) {
let txn = Transaction::new(ctx.ndb).expect("txn");
cache.init_conversations(
@@ -148,6 +150,7 @@ fn initialize(ctx: &mut AppContext, cache: &mut ConversationCache, is_narrow: bo
cache.state = ConversationListState::Initialized(sub);
}
+#[profiling::function]
fn update_initialized(ctx: &mut AppContext, cache: &mut ConversationCache, sub: Subscription) {
let notes = ctx.ndb.poll_for_notes(sub, 10);
let txn = Transaction::new(ctx.ndb).expect("txn");
diff --git a/crates/notedeck_messages/src/nip17/mod.rs b/crates/notedeck_messages/src/nip17/mod.rs
@@ -140,6 +140,7 @@ fn randomized_timestamp(rng: &mut OsRng) -> u64 {
now.saturating_sub(tweak)
}
+#[profiling::function]
pub fn get_participants<'a>(note: &Note<'a>) -> Vec<&'a [u8; 32]> {
let mut participants = get_p_tags(note);
let chat_message_sender = note.pubkey();