Record timed startup stages through the first UI frame and preserve explicit renderer overrides

This commit is contained in:
Codex committed 2026-11-30 13:13:31 +01:00
1 parent a6d31b9100
commit 90a460cc7d
5 files changed
+51 -4

No files matched your search

+1
View File
@@ -76,6 +76,7 @@
PdfCraft is part of [ArtCraft](https://getartcraft.com). Come say hello, get help and follow development: PdfCraft is part of [ArtCraft](https://getartcraft.com). Come say hello, get help and follow development:
- **Discord: [discord.gg/artcraft](https://discord.gg/artcraft)**. This is the fastest way to get help and share feedback. The app has a Discord button in its title bar. - **Discord: [discord.gg/artcraft](https://discord.gg/artcraft)**. This is the fastest way to get help and share feedback. The app has a Discord button in its title bar.
- [Collect a Windows startup log](docs/windows-renderer-startup.md#if-the-window-freezes-at-startup) if the app opens a frozen window.
- **Web page:** [getartcraft.com/apps/pdfcraft](https://getartcraft.com/apps/pdfcraft) - **Web page:** [getartcraft.com/apps/pdfcraft](https://getartcraft.com/apps/pdfcraft)
- **Source:** [github.com/storytold/pdfcraft](https://github.com/storytold/pdfcraft) - **Source:** [github.com/storytold/pdfcraft](https://github.com/storytold/pdfcraft)
+22 -4
View File
@@ -333,6 +333,8 @@ fn main() -> eframe::Result {
// window. // window.
// Absolute for this instance too: links relative to a document resolve against its folder, // Absolute for this instance too: links relative to a document resolve against its folder,
// never the working directory. // never the working directory.
let startup_time = std::time::Instant::now();
startup_stage(startup_time, "claiming application instance");
let files = single_instance::absolute(&files); let files = single_instance::absolute(&files);
let instance = match single_instance::claim(&files, may_hand_off, combine, launch_profile::current().root()) { let instance = match single_instance::claim(&files, may_hand_off, combine, launch_profile::current().root()) {
single_instance::Claim::HandedOff => return Ok(()), single_instance::Claim::HandedOff => return Ok(()),
@@ -360,6 +362,7 @@ fn main() -> eframe::Result {
// unless `PDFCRAFT_TITLEBAR` overrides them. The store is read here and opened again by the // unless `PDFCRAFT_TITLEBAR` overrides them. The store is read here and opened again by the
// app (each window attempt opens its own: the OpenGL retry runs the creator again). // app (each window attempt opens its own: the OpenGL retry runs the creator again).
// The interface language is read the same way, for the fonts the runtime installs with. // The interface language is read the same way, for the fonts the runtime installs with.
startup_stage(startup_time, "reading startup preferences");
let (title_bar, saved_lang) = { let (title_bar, saved_lang) = {
let settings = pdfcraft_ui_egui::settings::open(); let settings = pdfcraft_ui_egui::settings::open();
let saved = settings.get(); let saved = settings.get();
@@ -371,7 +374,7 @@ fn main() -> eframe::Result {
let frame = craft::window::policy::decide_for(craft::window::Prefix::new("PDFCRAFT"), craft::window::policy::Backend::from_env(), title_bar); let frame = craft::window::policy::decide_for(craft::window::Prefix::new("PDFCRAFT"), craft::window::policy::Backend::from_env(), title_bar);
let lang = startup_lang(saved_lang.as_deref(), &options); let lang = startup_lang(saved_lang.as_deref(), &options);
let choice = renderer_choice(std::env::var("PDFCRAFT_RENDERER").ok().as_deref()); let choice = renderer_choice(std::env::var("PDFCRAFT_RENDERER").ok().as_deref());
let launch = Launch { files, options, control, create_images, combine, frame, lang, two_paged, nightly_watch: nightly_watch.clone() }; let launch = Launch { startup_time, files, options, control, create_images, combine, frame, lang, two_paged, nightly_watch: nightly_watch.clone() };
// Finder, Open With and the Dock deliver files as Apple events, not arguments; catch the one // Finder, Open With and the Dock deliver files as Apple events, not arguments; catch the one
// that launched us as well as later ones. Lives until the event loop returns. // that launched us as well as later ones. Lives until the event loop returns.
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
@@ -379,6 +382,7 @@ fn main() -> eframe::Result {
// Set once the app is created, which is after the renderer has started. // Set once the app is created, which is after the renderer has started.
let started = Rc::new(Cell::new(false)); let started = Rc::new(Cell::new(false));
let first = if choice == RendererChoice::Gl { eframe::Renderer::Glow } else { eframe::Renderer::Wgpu }; let first = if choice == RendererChoice::Gl { eframe::Renderer::Glow } else { eframe::Renderer::Wgpu };
startup_stage(startup_time, if choice == RendererChoice::Gl { "initializing OpenGL" } else { "initializing wgpu" });
let result = eframe::run_native( let result = eframe::run_native(
app_title(), app_title(),
native_options(launch.integrated(), first), native_options(launch.integrated(), first),
@@ -397,6 +401,7 @@ fn main() -> eframe::Result {
// Old or unusual GPUs and drivers (#461, #435, #392) can't give wgpu a device; OpenGL // Old or unusual GPUs and drivers (#461, #435, #392) can't give wgpu a device; OpenGL
// usually still works there, so that's better than quitting. // usually still works there, so that's better than quitting.
log::error!("the GPU renderer (wgpu) didn't start: {e}. Starting with OpenGL instead; set PDFCRAFT_RENDERER=gl to skip wgpu."); log::error!("the GPU renderer (wgpu) didn't start: {e}. Starting with OpenGL instead; set PDFCRAFT_RENDERER=gl to skip wgpu.");
startup_stage(startup_time, "retrying with OpenGL");
eframe::run_native( eframe::run_native(
app_title(), app_title(),
native_options(launch.integrated(), eframe::Renderer::Glow), native_options(launch.integrated(), eframe::Renderer::Glow),
@@ -415,6 +420,10 @@ fn main() -> eframe::Result {
final_result final_result
} }
fn startup_stage(start: std::time::Instant, stage: &str) {
log::info!(target: "pdfcraft::startup", "+{} ms: {stage}", start.elapsed().as_millis());
}
/// Which renderer to start with, from `PDFCRAFT_RENDERER`. /// Which renderer to start with, from `PDFCRAFT_RENDERER`.
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum RendererChoice { enum RendererChoice {
@@ -527,6 +536,7 @@ fn native_options(integrated: bool, renderer: eframe::Renderer) -> eframe::Nativ
/// What the command line asked for, kept so a second run (with OpenGL) can start the same way. /// What the command line asked for, kept so a second run (with OpenGL) can start the same way.
#[derive(Clone)] #[derive(Clone)]
struct Launch { struct Launch {
startup_time: std::time::Instant,
files: Vec<String>, files: Vec<String>,
options: Vec<(String, String)>, options: Vec<(String, String)>,
/// The control server's port and token, when `--control` asked for one. /// The control server's port and token, when `--control` asked for one.
@@ -626,9 +636,10 @@ fn app_creator<'a>(
instance: Option<&'a single_instance::Server>, instance: Option<&'a single_instance::Server>,
#[cfg(target_os = "macos")] apple_events: &'a apple_events::AppleEvents, #[cfg(target_os = "macos")] apple_events: &'a apple_events::AppleEvents,
) -> eframe::AppCreator<'a> { ) -> eframe::AppCreator<'a> {
let Launch { files, options, control, create_images, combine, frame, lang, two_paged, nightly_watch } = launch; let Launch { startup_time, files, options, control, create_images, combine, frame, lang, two_paged, nightly_watch } = launch;
Box::new(move |cc| { Box::new(move |cc| {
started.set(true); started.set(true);
startup_stage(startup_time, "renderer ready, installing fonts and runtime");
install_runtime(cc, frame, lang)?; install_runtime(cc, frame, lang)?;
let ctx = cc.egui_ctx.clone(); let ctx = cc.egui_ctx.clone();
let wake = craft::host::Wake::new(move || ctx.request_repaint()); let wake = craft::host::Wake::new(move || ctx.request_repaint());
@@ -642,6 +653,7 @@ fn app_creator<'a>(
// drains them into the intake. // drains them into the intake.
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
let apple_events_poll = apple_events.connect(intake.sender(), &cc.egui_ctx); let apple_events_poll = apple_events.connect(intake.sender(), &cc.egui_ctx);
startup_stage(startup_time, "initializing application and recovery");
let mut app = PdfCraftApp::with_intake(&cc.egui_ctx, intake); let mut app = PdfCraftApp::with_intake(&cc.egui_ctx, intake);
let exit_watch = nightly_watch.clone(); let exit_watch = nightly_watch.clone();
app.at_exit = Some(Box::new(move || nightly_session::finish_once(&exit_watch, true))); app.at_exit = Some(Box::new(move || nightly_session::finish_once(&exit_watch, true)));
@@ -653,6 +665,7 @@ fn app_creator<'a>(
app.units = pdfcraft_ui_egui::units::Unit::system(); app.units = pdfcraft_ui_egui::units::Unit::system();
// The system's reopen-windows choice (macOS) starts the preference; a saved choice replaces it. // The system's reopen-windows choice (macOS) starts the preference; a saved choice replaces it.
app.reopen_last_session = reopen::system_default(); app.reopen_last_session = reopen::system_default();
startup_stage(startup_time, "applying preferences");
let settings = pdfcraft_ui_egui::settings::open(); let settings = pdfcraft_ui_egui::settings::open();
app.apply_settings(settings.get()); app.apply_settings(settings.get());
app.attach_settings(settings); app.attach_settings(settings);
@@ -698,6 +711,7 @@ fn app_creator<'a>(
if let Some(warning) = &pdfcraft_ui_egui::settings::resolution().warning { if let Some(warning) = &pdfcraft_ui_egui::settings::resolution().warning {
app.notify(warning.clone()); app.notify(warning.clone());
} }
startup_stage(startup_time, "restoring session and opening requested documents");
let defer_layout = two_paged && !files.is_empty() && !create_images; let defer_layout = two_paged && !files.is_empty() && !create_images;
if create_images { if create_images {
if let Err(e) = app.begin_image_import_paths(&cc.egui_ctx, &files) { if let Err(e) = app.begin_image_import_paths(&cc.egui_ctx, &files) {
@@ -718,6 +732,8 @@ fn app_creator<'a>(
log::warn!("--{k} {v}: {e}"); log::warn!("--{k} {v}: {e}");
} }
} }
startup_stage(startup_time, "entering UI event loop");
app.startup_time = Some(startup_time);
Ok(Box::new(app)) Ok(Box::new(app))
}) })
} }
@@ -786,6 +802,8 @@ fn configure_gpu(native: &mut eframe::NativeOptions) {
// no display names its GPU, as over Remote Desktop; `pick_adapter` then ranks by kind, // no display names its GPU, as over Remote Desktop; `pick_adapter` then ranks by kind,
// most frugal first, as wgpu's own low-power choice does. // most frugal first, as wgpu's own low-power choice does.
if !displays.is_empty() || compositor.is_some() || cfg!(target_os = "windows") { if !displays.is_empty() || compositor.is_some() || cfg!(target_os = "windows") {
let explicit_renderer = renderer_choice(std::env::var("PDFCRAFT_RENDERER").ok().as_deref()) == RendererChoice::Wgpu;
let backend_chosen = explicit_renderer || std::env::var_os("WGPU_BACKEND").is_some();
setup.native_adapter_selector = Some(std::sync::Arc::new(move |adapters, surface| { setup.native_adapter_selector = Some(std::sync::Arc::new(move |adapters, surface| {
let usable: Vec<&eframe::wgpu::Adapter> = adapters.iter().filter(|a| surface.is_none_or(|s| a.is_surface_supported(s))).collect(); let usable: Vec<&eframe::wgpu::Adapter> = adapters.iter().filter(|a| surface.is_none_or(|s| a.is_surface_supported(s))).collect();
let infos: Vec<(u32, u32, eframe::wgpu::DeviceType, eframe::wgpu::Backend)> = usable let infos: Vec<(u32, u32, eframe::wgpu::DeviceType, eframe::wgpu::Backend)> = usable
@@ -797,7 +815,7 @@ fn configure_gpu(native: &mut eframe::NativeOptions) {
.collect(); .collect();
let picked = pick_adapter(&infos, &displays, compositor).and_then(|i| usable.get(i)).map(|a| (*a).clone()); let picked = pick_adapter(&infos, &displays, compositor).and_then(|i| usable.get(i)).map(|a| (*a).clone());
if let Some(a) = &picked if let Some(a) = &picked
&& !wgpu_draws_with(a.get_info().backend, cfg!(target_os = "windows"), std::env::var_os("WGPU_BACKEND").is_some()) && !wgpu_draws_with(a.get_info().backend, cfg!(target_os = "windows"), backend_chosen)
{ {
log::warn!( log::warn!(
"wgpu found no Direct3D 12 adapter for {}, only its OpenGL backend: drawing with eframe's OpenGL renderer instead", "wgpu found no Direct3D 12 adapter for {}, only its OpenGL backend: drawing with eframe's OpenGL renderer instead",
@@ -830,7 +848,7 @@ fn configure_gpu(native: &mut eframe::NativeOptions) {
/// Bridge, and there that backend fails in `Surface::configure` a few seconds after the window /// Bridge, and there that backend fails in `Surface::configure` a few seconds after the window
/// opens: too late for the start-up retry with OpenGL, so the app closed (#519, #4134, #5553). /// opens: too late for the start-up retry with OpenGL, so the app closed (#519, #4134, #5553).
/// eframe's own OpenGL renderer works on the same GPUs, so wgpu declines and that retry takes over. /// eframe's own OpenGL renderer works on the same GPUs, so wgpu declines and that retry takes over.
/// A backend asked for with `WGPU_BACKEND` (`backend_chosen`) is kept. /// An explicit `PDFCRAFT_RENDERER=wgpu` or `WGPU_BACKEND` selection (`backend_chosen`) is kept.
fn wgpu_draws_with(backend: eframe::wgpu::Backend, windows: bool, backend_chosen: bool) -> bool { fn wgpu_draws_with(backend: eframe::wgpu::Backend, windows: bool, backend_chosen: bool) -> bool {
!(windows && backend == eframe::wgpu::Backend::Gl && !backend_chosen) !(windows && backend == eframe::wgpu::Backend::Gl && !backend_chosen)
} }
+4
View File
@@ -370,6 +370,7 @@ impl PdfCraftApp {
reload_changed_files: true, reload_changed_files: true,
update_check_at_start: true, update_check_at_start: true,
at_exit: None, at_exit: None,
startup_time: None,
show_secured_notice: true, show_secured_notice: true,
text_links: true, text_links: true,
always_default_view: false, always_default_view: false,
@@ -747,6 +748,9 @@ impl eframe::App for PdfCraftApp {
let ctx = ui.ctx().clone(); let ctx = ui.ctx().clone();
self.guarded_frame(&ctx, |app| app.ui_unguarded(ui)); self.guarded_frame(&ctx, |app| app.ui_unguarded(ui));
self.end_ui(); self.end_ui();
if let Some(start) = self.startup_time.take() {
log::info!(target: "pdfcraft::startup", "+{} ms: first UI pass finished", start.elapsed().as_millis());
}
} }
} }
+2
View File
@@ -440,6 +440,8 @@ pub struct PdfCraftApp {
pub update_check_at_start: bool, pub update_check_at_start: bool,
/// Optional host cleanup invoked once in `eframe::App::on_exit` (e.g. Nightly session record). /// Optional host cleanup invoked once in `eframe::App::on_exit` (e.g. Nightly session record).
pub at_exit: Option<Box<dyn FnOnce()>>, pub at_exit: Option<Box<dyn FnOnce()>>,
/// Native launch time, consumed after the first UI pass for startup diagnostics.
pub startup_time: Option<std::time::Instant>,
/// Preferences: tell the user, above the pages, that a document is secured (its security /// Preferences: tell the user, above the pages, that a document is secured (its security
/// settings restrict changes). Off only hides that notice (#4035); kept in the settings. /// settings restrict changes). Off only hides that notice (#4035); kept in the settings.
pub show_secured_notice: bool, pub show_secured_notice: bool,
+22
View File
@@ -1,5 +1,27 @@
# Windows renderer startup errors and the OpenGL fallback # Windows renderer startup errors and the OpenGL fallback
## If the window freezes at startup
Keep the frozen window open. In File Explorer, paste `%APPDATA%\PdfCraft\data\logs` into the address bar. For a portable copy, open `PdfCraftData\logs` beside `pdfcraft.exe`. The current log is `pdfcraft.log`. Copy it before starting PdfCraft again. You can read it while the window is frozen.
From 0.23.1 onward, each `pdfcraft::startup` line records a stage and the elapsed milliseconds. The renderer lines identify the GPU and graphics backend. To extract those lines from the installed app, run this in PowerShell:
```powershell
Get-Content "$env:APPDATA\PdfCraft\data\logs\pdfcraft.log" |
Select-String 'pdfcraft::startup|drawing on |renderer:|the GPU renderer'
```
Include the last launch's matching lines, PdfCraft version, Windows version from `winver`, and whether you launched the Home screen or opened a PDF. The first UI pass means the application prepared the frame. It can still stall while the driver presents it. Review the excerpt before sharing it.
For a comparison, close PdfCraft, open PowerShell in the folder containing `pdfcraft.exe`, and run:
```powershell
$env:PDFCRAFT_RENDERER = 'gl'
.\pdfcraft.exe
```
Closing this PowerShell window clears the override. Report whether the same operation works with OpenGL.
## Reproduced failure ## Reproduced failure
On one Windows 11 Pro build 26200 host, the official PdfCraft 0.6.0 x86 installation and On one Windows 11 Pro build 26200 host, the official PdfCraft 0.6.0 x86 installation and