Three root causes, all fixed and verified on the Pixel 9 Pro: 1. Present phase (backend + renderer): VSYNC_LOCKED_RENDER defers the render to the vsync wake; RENDER_AHEAD presents the previous frame at the start of render() (phase = wake + ~1.1 ms) and holds the new frame one slot. Crash fix: a held wgpu frame must be PRESENTED, never merely dropped, before the next acquire (AlreadyAcquired panic at launch otherwise); discard_pending_frame presents too. 2. Full-res prefetch churn (src/lib.rs): the 8-slot full cache cycled through a ~20-cell viewport forever (137 decodes/20 s) and each eviction free()'d a 50 MB Vec on the UI thread (20-52 ms CPU spikes, ~7/s = the residual SLOWEV NonMain jank). Fix: 60 s tombstone cooldown on evicted paths (idle prefetch skips, urgent tap bypasses) + off-thread reaper for the freed blobs (insert: 21 ms -> 4 us). 3. (earlier) Skia final flush + Mailbox present mode (vendor, M3). Instrumentation (all behind --features perf): OTHR/INVK/INVK_TAG/FLCK lines for cross-thread closure timing and push-site tagging. Warm measured swipe, 8580-file grid: cadence median 8.33 ms (exact 120 Hz), p99 15.5 ms, 5/552 gaps >16.7 ms (0.9%, max 28.3 ms, zero >33 ms); PRES phase median ~994 us, zero late frames. Docs updated (docs/BUGS/scroll-jank-120hz.md, full scorecard + line reference). Also: vendored i-slint-core + wgpu-hal (vkshim interposition patch), vkshim profiling tooling, backend made a non-optional dep, debuggable flag for simpleperf (REMOVE before shipping).
105 lines
3.4 KiB
Rust
105 lines
3.4 KiB
Rust
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
|
|
|
|
/// Location information attached to a log message.
|
|
#[derive(Clone, Debug)]
|
|
pub struct LogMessageLocation<'a> {
|
|
/// The file path of the source that emitted the log message
|
|
pub path: &'a str,
|
|
/// the line number of the call that emitted the log message (1-based)
|
|
pub line: usize,
|
|
/// The column of the call that emitted the log message (1-based)
|
|
pub column: usize,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
#[non_exhaustive]
|
|
pub enum LogMessageSource {
|
|
/// The message originates from Slint source code (e.g. the `debug()` function in Slint)
|
|
SlintCode,
|
|
/// The message originates from the Slint runtime crates
|
|
///
|
|
/// For example if a file path could not be resolved at runtime.
|
|
Runtime,
|
|
}
|
|
|
|
/// Opaque log message, emitted by [`crate::debug_log!`] as well as the Slint `debug()` function.
|
|
pub struct LogMessage<'a> {
|
|
source: LogMessageSource,
|
|
location: Option<LogMessageLocation<'a>>,
|
|
arguments: core::fmt::Arguments<'a>,
|
|
}
|
|
|
|
impl<'a> LogMessage<'a> {
|
|
pub fn new(
|
|
source: LogMessageSource,
|
|
location: Option<LogMessageLocation<'a>>,
|
|
arguments: core::fmt::Arguments<'a>,
|
|
) -> Self {
|
|
Self { source, location, arguments }
|
|
}
|
|
|
|
pub fn source(&self) -> LogMessageSource {
|
|
self.source
|
|
}
|
|
|
|
pub fn location(&self) -> Option<LogMessageLocation<'_>> {
|
|
self.location.clone()
|
|
}
|
|
|
|
pub fn message_arguments(&self) -> core::fmt::Arguments<'a> {
|
|
self.arguments
|
|
}
|
|
}
|
|
|
|
/// Log message handler type stored in a [`crate::SlintContext`].
|
|
pub type LogMessageHandler = alloc::boxed::Box<dyn for<'a> Fn(LogMessage<'a>) + 'static>;
|
|
|
|
#[doc(hidden)]
|
|
pub fn log_message(message: LogMessage) {
|
|
crate::context::GLOBAL_CONTEXT.with(|p| match p.get() {
|
|
Some(ctx) => ctx.dispatch_log_message(message),
|
|
None => default_log_message(message.arguments),
|
|
});
|
|
}
|
|
|
|
#[doc(hidden)]
|
|
pub fn default_log_message(_arguments: core::fmt::Arguments) {
|
|
cfg_if::cfg_if! {
|
|
if #[cfg(feature = "log")] {
|
|
log::debug!("{_arguments}");
|
|
} else if #[cfg(target_arch = "wasm32")] {
|
|
use wasm_bindgen::prelude::*;
|
|
use std::string::ToString;
|
|
|
|
#[wasm_bindgen]
|
|
extern "C" {
|
|
#[wasm_bindgen(js_namespace = console)]
|
|
pub fn log(s: &str);
|
|
}
|
|
|
|
log(&_arguments.to_string());
|
|
} else if #[cfg(feature = "std")] {
|
|
use std::io::Write;
|
|
// We were seeing intermittent, albeit very rare, crashes due to `eprintln` panicking
|
|
// if the write to stderr fails. Since this is just for debug printing, it's safe
|
|
// to silently drop this if we can't write (since it wouldn't be written to stderr
|
|
// anyway)
|
|
let _ = writeln!(std::io::stderr(), "{_arguments}");
|
|
}
|
|
}
|
|
}
|
|
|
|
#[macro_export]
|
|
/// This macro allows producing debug output that will appear on stderr in regular builds
|
|
/// and in the console log for wasm builds.
|
|
macro_rules! debug_log {
|
|
($($t:tt)*) => ($crate::debug_log::log_message(
|
|
$crate::debug_log::LogMessage::new(
|
|
$crate::debug_log::LogMessageSource::Runtime,
|
|
None,
|
|
format_args!($($t)*),
|
|
)
|
|
))
|
|
}
|