switch to profiling crates

This switches to the profiling crate for compatible
profiling between rust libraries.

To enable:

$ cargo build --release --features puffin

Feel free to experiment with other profiling backends
as well! Would be great to get tracy working.
This commit is contained in:
William Casarin
2025-03-23 10:43:49 -07:00
parent 7b9e6f180c
commit 54deb2dd88
20 changed files with 46 additions and 80 deletions

View File

@@ -60,6 +60,7 @@ impl egui::Widget for &mut NoteContents<'_, '_> {
/// Render an inline note preview with a border. These are used when
/// notes are references within a note
#[allow(clippy::too_many_arguments)]
#[profiling::function]
pub fn render_note_preview(
ui: &mut egui::Ui,
note_context: &mut NoteContext,
@@ -68,9 +69,6 @@ pub fn render_note_preview(
parent: NoteKey,
note_options: NoteOptions,
) -> NoteResponse {
#[cfg(feature = "profiling")]
puffin::profile_function!();
let note = if let Ok(note) = note_context.ndb.get_note_by_id(txn, id) {
// TODO: support other preview kinds
if note.kind() == 1 {
@@ -118,6 +116,7 @@ pub fn render_note_preview(
}
#[allow(clippy::too_many_arguments)]
#[profiling::function]
fn render_note_contents(
ui: &mut egui::Ui,
note_context: &mut NoteContext,
@@ -125,9 +124,6 @@ fn render_note_contents(
note: &Note,
options: NoteOptions,
) -> NoteResponse {
#[cfg(feature = "profiling")]
puffin::profile_function!();
let note_key = note.key().expect("todo: implement non-db notes");
let selectable = options.has_selectable_text();
let mut images: Vec<(String, MediaCacheType)> = vec![];
@@ -197,8 +193,6 @@ fn render_note_contents(
},
BlockType::Hashtag => {
#[cfg(feature = "profiling")]
puffin::profile_scope!("hashtag contents");
let resp = ui.colored_label(link_color, format!("#{}", block.as_str()));
if resp.clicked() {
@@ -223,8 +217,6 @@ fn render_note_contents(
}
};
if hide_media || !found_supported() {
#[cfg(feature = "profiling")]
puffin::profile_scope!("url contents");
ui.add(Hyperlink::from_label_and_url(
RichText::new(block.as_str()).color(link_color),
block.as_str(),
@@ -233,8 +225,6 @@ fn render_note_contents(
}
BlockType::Text => {
#[cfg(feature = "profiling")]
puffin::profile_scope!("text contents");
if options.has_scramble_text() {
ui.add(egui::Label::new(rot13(block.as_str())).selectable(selectable));
} else {

View File

@@ -97,10 +97,8 @@ impl NoteContextButton {
Self::max_distance_between_circles() / Self::expansion_multiple()
}
#[profiling::function]
pub fn show(ui: &mut egui::Ui, note_key: NoteKey, put_at: Rect) -> egui::Response {
#[cfg(feature = "profiling")]
puffin::profile_function!();
let id = ui.id().with(("more_options_anim", note_key));
let min_radius = Self::min_radius();
@@ -138,13 +136,11 @@ impl NoteContextButton {
response
}
#[profiling::function]
pub fn menu(
ui: &mut egui::Ui,
button_response: egui::Response,
) -> Option<NoteContextSelection> {
#[cfg(feature = "profiling")]
puffin::profile_function!();
let mut context_selection: Option<NoteContextSelection> = None;
stationary_arbitrary_menu_button(ui, button_response, |ui| {

View File

@@ -307,15 +307,13 @@ impl<'a, 'd> NoteView<'a, 'd> {
}
}
#[profiling::function]
fn note_header(
ui: &mut egui::Ui,
note_cache: &mut NoteCache,
note: &Note,
profile: &Result<nostrdb::ProfileRecord<'_>, nostrdb::Error>,
) {
#[cfg(feature = "profiling")]
puffin::profile_function!();
let note_key = note.key().unwrap();
ui.horizontal(|ui| {
@@ -327,9 +325,8 @@ impl<'a, 'd> NoteView<'a, 'd> {
});
}
#[profiling::function]
fn show_standard(&mut self, ui: &mut egui::Ui) -> NoteResponse {
#[cfg(feature = "profiling")]
puffin::profile_function!();
let note_key = self.note.key().expect("todo: support non-db notes");
let txn = self.note.txn().expect("todo: support non-db notes");
@@ -563,14 +560,12 @@ fn note_hitbox_clicked(
}
}
#[profiling::function]
fn render_note_actionbar(
ui: &mut egui::Ui,
note_id: &[u8; 32],
note_key: NoteKey,
) -> egui::InnerResponse<Option<NoteAction>> {
#[cfg(feature = "profiling")]
puffin::profile_function!();
ui.horizontal(|ui| {
let reply_resp = reply_button(ui, note_key);
let quote_resp = quote_repost_button(ui, note_key);
@@ -590,14 +585,12 @@ fn secondary_label(ui: &mut egui::Ui, s: impl Into<String>) {
ui.add(Label::new(RichText::new(s).size(10.0).color(color)));
}
#[profiling::function]
fn render_reltime(
ui: &mut egui::Ui,
note_cache: &mut CachedNote,
before: bool,
) -> egui::InnerResponse<()> {
#[cfg(feature = "profiling")]
puffin::profile_function!();
ui.horizontal(|ui| {
if before {
secondary_label(ui, "");

View File

@@ -8,6 +8,7 @@ use nostrdb::{Note, NoteReply, Transaction};
use super::{contents::NoteContext, NoteOptions};
#[must_use = "Please handle the resulting note action"]
#[profiling::function]
pub fn reply_desc(
ui: &mut egui::Ui,
txn: &Transaction,
@@ -15,9 +16,6 @@ pub fn reply_desc(
note_context: &mut NoteContext,
note_options: NoteOptions,
) -> Option<NoteAction> {
#[cfg(feature = "profiling")]
puffin::profile_function!();
let mut note_action: Option<NoteAction> = None;
let size = 10.0;
let selectable = false;