Debug builds seem to be really slow to render due to excessive logging via tracing #2273
Replies: 4 comments 1 reply
-
Leptos 0.6.4, Rust 1.75, stable |
Beta Was this translation helpful? Give feedback.
-
For some reason, this makes a huge difference: let config = WASMLayerConfigBuilder::new()
.set_max_level(Level::WARN)
.set_report_logs_in_timings(false)
.set_console_config(tracing_wasm::ConsoleConfig::ReportWithoutConsoleColor)
.build();
tracing::subscriber::set_global_default(Registry::default().with(WASMLayer::new(config)))
.expect("WASM logger failed"); But the exact same code with the max level set to |
Beta Was this translation helpful? Give feedback.
-
I can't say I've ever noticed any rendering speed issues in debug mode, but then again I usually don't have a tracing subscriber running, so I believe you. You're probably right about the tracing spans. Everything is instrumented in a pretty detailed way, to allow for ongoing work to build additional dev tooling. That said, if tweaking the max level is allowed then it seems like it's not the instrumentation per se. I also don't think Leptos instruments anything with a level about All the tracing instrumentation is omitted from release mode in CSR/hydration, hence the change you're seeing there. |
Beta Was this translation helpful? Give feedback.
-
For anyone else who might bump into this, the following log filtering may be useful: use tracing::level_filters::LevelFilter;
use tracing_subscriber::{filter, layer::SubscriberExt, Layer, Registry};
use tracing_wasm::{WASMLayer, WASMLayerConfigBuilder};
// Put this somewhere global
const PACKAGE_NAME: &str = env!("CARGO_PKG_NAME");
// put this at the top of main
let filter_fn = filter::filter_fn(|metadata| {
let mut level_filter = LevelFilter::WARN;
// Allow all logs from this app only.
if metadata.target().starts_with(PACKAGE_NAME) {
level_filter = LevelFilter::TRACE;
}
metadata.level() <= &level_filter
});
let config = WASMLayerConfigBuilder::new()
.set_report_logs_in_timings(false)
.set_console_config(tracing_wasm::ConsoleConfig::ReportWithoutConsoleColor)
.build();
tracing::subscriber::set_global_default(
Registry::default().with(WASMLayer::new(config).with_filter(filter_fn)),
)
.expect("WASM logger failed"); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm running leptos with CSR via
trunk serve
and trying to render pages with a reasonable number of components, but no lists or data-heavy things. Debug rendering seems quite slow. The console shows a lot of TRACE logs showing "calling on() click".If I remove the line to install the tracing logger, everything feels pretty quick. So it seems tracing adds quite a bit of overhead here.
Things I've tried:
max_level_debug
andrelease_max_level_warn
. Slightly better, but still quite slowtracing_wasm::set_as_global_default()
- this also works. Rendering is pretty fast even in debug builds.Any recommendations for removing this logging performance hit?
Beta Was this translation helpful? Give feedback.
All reactions