notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit 0dda26791ac0a375914def518bc4a6c25e3137a5
parent 7e73ed276097fc621b83eab8e704f446e427d2d1
Author: William Casarin <jb55@jb55.com>
Date:   Sun,  3 Aug 2025 20:12:31 -0700

perf: a few micro optimizations

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mcrates/notedeck_ui/src/lib.rs | 4++--
Mcrates/notedeck_ui/src/note/contents.rs | 5+++++
Mcrates/notedeck_ui/src/note/mod.rs | 28++++++++++++++--------------
Mcrates/notedeck_ui/src/note/reply_description.rs | 2+-
4 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/crates/notedeck_ui/src/lib.rs b/crates/notedeck_ui/src/lib.rs @@ -56,7 +56,7 @@ pub fn hline_with_width(ui: &egui::Ui, range: egui::Rangef) { ui.painter().hline(range, resize_y, stroke); } -pub fn secondary_label(ui: &mut egui::Ui, s: impl Into<String>) { +pub fn secondary_label(ui: &mut egui::Ui, s: impl Into<String>) -> egui::Response { let color = ui.style().visuals.noninteractive().fg_stroke.color; - ui.add(Label::new(RichText::new(s).size(10.0).color(color)).selectable(false)); + ui.add(Label::new(RichText::new(s).size(10.0).color(color)).selectable(false)) } diff --git a/crates/notedeck_ui/src/note/contents.rs b/crates/notedeck_ui/src/note/contents.rs @@ -206,6 +206,7 @@ fn render_undecorated_note_contents<'a>( match block.blocktype() { BlockType::MentionBech32 => match block.as_mention().unwrap() { Mention::Profile(profile) => { + profiling::scope!("profile-block"); let act = crate::Mention::new( note_context.ndb, note_context.img_cache, @@ -220,6 +221,7 @@ fn render_undecorated_note_contents<'a>( } Mention::Pubkey(npub) => { + profiling::scope!("pubkey-block"); let act = crate::Mention::new( note_context.ndb, note_context.img_cache, @@ -251,6 +253,7 @@ fn render_undecorated_note_contents<'a>( }, BlockType::Hashtag => { + profiling::scope!("hashtag-block"); if block.as_str().trim().is_empty() { continue; } @@ -268,6 +271,7 @@ fn render_undecorated_note_contents<'a>( } BlockType::Url => { + profiling::scope!("url-block"); let mut found_supported = || -> bool { let url = block.as_str(); @@ -297,6 +301,7 @@ fn render_undecorated_note_contents<'a>( } BlockType::Text => { + profiling::scope!("text-block"); // truncate logic let mut truncate = false; let block_str = if options.contains(NoteOptions::Truncate) diff --git a/crates/notedeck_ui/src/note/mod.rs b/crates/notedeck_ui/src/note/mod.rs @@ -240,7 +240,7 @@ impl<'a, 'd> NoteView<'a, 'd> { let (_id, rect) = ui.allocate_space(egui::vec2(50.0, 20.0)); ui.allocate_rect(rect, Sense::hover()); ui.put(rect, |ui: &mut egui::Ui| { - render_notetime(ui, self.note_context.i18n, self.note.created_at(), false).response + render_notetime(ui, self.note_context.i18n, self.note.created_at(), false) }); let (_id, rect) = ui.allocate_space(egui::vec2(150.0, 20.0)); ui.allocate_rect(rect, Sense::hover()); @@ -398,7 +398,7 @@ impl<'a, 'd> NoteView<'a, 'd> { let response = ui .add(Username::new(i18n, profile.as_ref().ok(), note.pubkey()).abbreviated(20)); if !flags.contains(NoteOptions::FullCreatedDate) { - return render_notetime(ui, i18n, note.created_at(), true).response; + return render_notetime(ui, i18n, note.created_at(), true); } response }) @@ -892,18 +892,18 @@ fn render_notetime( i18n: &mut Localization, created_at: u64, before: bool, -) -> egui::InnerResponse<()> { - ui.horizontal(|ui| { - if before { - secondary_label(ui, "⋅"); - } - - secondary_label(ui, notedeck::time_ago_since(i18n, created_at)); - - if !before { - secondary_label(ui, "⋅"); - } - }) +) -> Response { + if before { + secondary_label( + ui, + format!(" ⋅ {}", notedeck::time_ago_since(i18n, created_at)), + ) + } else { + secondary_label( + ui, + format!("{} ⋅ ", notedeck::time_ago_since(i18n, created_at)), + ) + } } fn reply_button(ui: &mut egui::Ui, i18n: &mut Localization, note_key: NoteKey) -> egui::Response { diff --git a/crates/notedeck_ui/src/note/reply_description.rs b/crates/notedeck_ui/src/note/reply_description.rs @@ -116,7 +116,7 @@ fn render_text_segments( let link_color = visuals.hyperlink_color; for segment in segments { - match segment { + match &segment { TextSegment::Plain(text) => { ui.add( Label::new(RichText::new(text).size(size).color(color)).selectable(selectable),