perf: profiling note content rendering

Made some small speed improvements

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-04-22 08:58:30 -07:00
parent c944cac810
commit 32923abfc2

View File

@@ -53,6 +53,9 @@ fn render_note_preview(
id: &[u8; 32], id: &[u8; 32],
_id_str: &str, _id_str: &str,
) -> egui::Response { ) -> egui::Response {
#[cfg(feature = "profiling")]
puffin::profile_function!();
let note = if let Ok(note) = app.ndb.get_note_by_id(txn, id) { let note = if let Ok(note) = app.ndb.get_note_by_id(txn, id) {
// TODO: support other preview kinds // TODO: support other preview kinds
if note.kind() == 1 { if note.kind() == 1 {
@@ -123,6 +126,9 @@ fn render_note_contents(
match block.blocktype() { match block.blocktype() {
BlockType::MentionBech32 => match block.as_mention().unwrap() { BlockType::MentionBech32 => match block.as_mention().unwrap() {
Mention::Pubkey(npub) => { Mention::Pubkey(npub) => {
#[cfg(feature = "profiling")]
puffin::profile_scope!("pubkey contents");
ui.horizontal(|ui| { ui.horizontal(|ui| {
let profile = damus.ndb.get_profile_by_pubkey(txn, npub.pubkey()).ok(); let profile = damus.ndb.get_profile_by_pubkey(txn, npub.pubkey()).ok();
@@ -154,17 +160,14 @@ fn render_note_contents(
} }
_ => { _ => {
ui.colored_label(colors::PURPLE, "@"); ui.colored_label(colors::PURPLE, format!("@{}", &block.as_str()[4..16]));
ui.colored_label(colors::PURPLE, &block.as_str()[4..16]);
} }
}, },
BlockType::Hashtag => { BlockType::Hashtag => {
ui.horizontal(|ui| { #[cfg(feature = "profiling")]
ui.spacing_mut().item_spacing.x = 0.0; puffin::profile_scope!("hashtag contents");
ui.colored_label(colors::PURPLE, "#"); ui.colored_label(colors::PURPLE, format!("#{}", block.as_str()));
ui.colored_label(colors::PURPLE, block.as_str());
});
} }
BlockType::Url => { BlockType::Url => {
@@ -174,6 +177,8 @@ fn render_note_contents(
images.push(url); images.push(url);
} else { } else {
*/ */
#[cfg(feature = "profiling")]
puffin::profile_scope!("url contents");
ui.add(Hyperlink::from_label_and_url( ui.add(Hyperlink::from_label_and_url(
RichText::new(block.as_str()).color(colors::PURPLE), RichText::new(block.as_str()).color(colors::PURPLE),
block.as_str(), block.as_str(),
@@ -182,6 +187,8 @@ fn render_note_contents(
} }
BlockType::Text => { BlockType::Text => {
#[cfg(feature = "profiling")]
puffin::profile_scope!("text contents");
ui.label(block.as_str()); ui.label(block.as_str());
} }