Skip to content

Commit

Permalink
perf: profiling note content rendering
Browse files Browse the repository at this point in the history
Made some small speed improvements

Signed-off-by: William Casarin <[email protected]>
  • Loading branch information
jb55 committed Apr 22, 2024
1 parent c944cac commit 32923ab
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/ui/note/contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ fn render_note_preview(
id: &[u8; 32],
_id_str: &str,
) -> egui::Response {
#[cfg(feature = "profiling")]
puffin::profile_function!();

let note = if let Ok(note) = app.ndb.get_note_by_id(txn, id) {
// TODO: support other preview kinds
if note.kind() == 1 {
Expand Down Expand Up @@ -123,6 +126,9 @@ fn render_note_contents(
match block.blocktype() {
BlockType::MentionBech32 => match block.as_mention().unwrap() {
Mention::Pubkey(npub) => {
#[cfg(feature = "profiling")]
puffin::profile_scope!("pubkey contents");

ui.horizontal(|ui| {
let profile = damus.ndb.get_profile_by_pubkey(txn, npub.pubkey()).ok();

Expand Down Expand Up @@ -154,17 +160,14 @@ fn render_note_contents(
}

_ => {
ui.colored_label(colors::PURPLE, "@");
ui.colored_label(colors::PURPLE, &block.as_str()[4..16]);
ui.colored_label(colors::PURPLE, format!("@{}", &block.as_str()[4..16]));
}
},

BlockType::Hashtag => {
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = 0.0;
ui.colored_label(colors::PURPLE, "#");
ui.colored_label(colors::PURPLE, block.as_str());
});
#[cfg(feature = "profiling")]
puffin::profile_scope!("hashtag contents");
ui.colored_label(colors::PURPLE, format!("#{}", block.as_str()));
}

BlockType::Url => {
Expand All @@ -174,6 +177,8 @@ fn render_note_contents(
images.push(url);
} else {
*/
#[cfg(feature = "profiling")]
puffin::profile_scope!("url contents");
ui.add(Hyperlink::from_label_and_url(
RichText::new(block.as_str()).color(colors::PURPLE),
block.as_str(),
Expand All @@ -182,6 +187,8 @@ fn render_note_contents(
}

BlockType::Text => {
#[cfg(feature = "profiling")]
puffin::profile_scope!("text contents");
ui.label(block.as_str());
}

Expand Down

0 comments on commit 32923ab

Please sign in to comment.