Detect and warn slow Debug implementations for Message

This commit is contained in:
Héctor Ramón Jiménez 2025-04-07 20:02:39 +02:00
parent 08f1133a03
commit dd6c99e1a4
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
3 changed files with 11 additions and 0 deletions

View file

@ -15,6 +15,7 @@ enable = ["dep:iced_beacon"]
[dependencies]
iced_core.workspace = true
log.workspace = true
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
iced_beacon.workspace = true

View file

@ -135,7 +135,16 @@ mod internal {
pub fn update(message: &impl std::fmt::Debug) -> Span {
let span = span(span::Stage::Update);
let start = Instant::now();
let message = format!("{message:?}");
let elapsed = start.elapsed();
if elapsed.as_millis() >= 1 {
log::warn!(
"Slow `Debug` implementation of `Message` (took {elapsed:?})!"
);
}
BEACON.log(client::Event::MessageLogged(if message.len() > 49 {
format!("{}...", &message[..49])