Detect and warn slow Debug implementations for Message
This commit is contained in:
parent
08f1133a03
commit
dd6c99e1a4
3 changed files with 11 additions and 0 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -2453,6 +2453,7 @@ version = "0.14.0-dev"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_beacon",
|
"iced_beacon",
|
||||||
"iced_core",
|
"iced_core",
|
||||||
|
"log",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ enable = ["dep:iced_beacon"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
iced_core.workspace = true
|
iced_core.workspace = true
|
||||||
|
log.workspace = true
|
||||||
|
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
iced_beacon.workspace = true
|
iced_beacon.workspace = true
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,16 @@ mod internal {
|
||||||
|
|
||||||
pub fn update(message: &impl std::fmt::Debug) -> Span {
|
pub fn update(message: &impl std::fmt::Debug) -> Span {
|
||||||
let span = span(span::Stage::Update);
|
let span = span(span::Stage::Update);
|
||||||
|
|
||||||
|
let start = Instant::now();
|
||||||
let message = format!("{message:?}");
|
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 {
|
BEACON.log(client::Event::MessageLogged(if message.len() > 49 {
|
||||||
format!("{}...", &message[..49])
|
format!("{}...", &message[..49])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue