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

This commit is contained in:
Codex
2026-11-30 13:13:31 +01:00
parent a6d31b9100
commit 90a460cc7d
5 changed files with 51 additions and 4 deletions
+1
View File
@@ -76,6 +76,7 @@
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.
- [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)
- **Source:** [github.com/storytold/pdfcraft](https://github.com/storytold/pdfcraft)
+22 -4
View File
@@ -333,6 +333,8 @@ fn main() -> eframe::Result {
// window.
// Absolute for this instance too: links relative to a document resolve against its folder,
// 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 instance = match single_instance::claim(&files, may_hand_off, combine, launch_profile::current().root()) {
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
// 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.
startup_stage(startup_time, "reading startup preferences");
let (title_bar, saved_lang) = {
let settings = pdfcraft_ui_egui::settings::open();
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 lang = startup_lang(saved_lang.as_deref(), &options);
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
// that launched us as well as later ones. Lives until the event loop returns.
#[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.
let started = Rc::new(Cell::new(false));
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(
app_title(),
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
// 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.");
startup_stage(startup_time, "retrying with OpenGL");
eframe::run_native(
app_title(),
native_options(launch.integrated(), eframe::Renderer::Glow),
@@ -415,6 +420,10 @@ fn main() -> eframe::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`.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
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.
#[derive(Clone)]
struct Launch {
startup_time: std::time::Instant,
files: Vec<String>,
options: Vec<(String, String)>,
/// 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>,
#[cfg(target_os = "macos")] apple_events: &'a apple_events::AppleEvents,
) -> 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| {
started.set(true);
startup_stage(startup_time, "renderer ready, installing fonts and runtime");
install_runtime(cc, frame, lang)?;
let ctx = cc.egui_ctx.clone();
let wake = craft::host::Wake::new(move || ctx.request_repaint());
@@ -642,6 +653,7 @@ fn app_creator<'a>(
// drains them into the intake.
#[cfg(target_os = "macos")]
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 exit_watch = nightly_watch.clone();
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();
// The system's reopen-windows choice (macOS) starts the preference; a saved choice replaces it.
app.reopen_last_session = reopen::system_default();
startup_stage(startup_time, "applying preferences");
let settings = pdfcraft_ui_egui::settings::open();
app.apply_settings(settings.get());
app.attach_settings(settings);
@@ -698,6 +711,7 @@ fn app_creator<'a>(
if let Some(warning) = &pdfcraft_ui_egui::settings::resolution().warning {
app.notify(warning.clone());
}
startup_stage(startup_time, "restoring session and opening requested documents");
let defer_layout = two_paged && !files.is_empty() && !create_images;
if create_images {
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}");
}
}
startup_stage(startup_time, "entering UI event loop");
app.startup_time = Some(startup_time);
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,
// most frugal first, as wgpu's own low-power choice does.
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| {
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
@@ -797,7 +815,7 @@ fn configure_gpu(native: &mut eframe::NativeOptions) {
.collect();
let picked = pick_adapter(&infos, &displays, compositor).and_then(|i| usable.get(i)).map(|a| (*a).clone());
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!(
"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
/// 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.
/// 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 {
!(windows && backend == eframe::wgpu::Backend::Gl && !backend_chosen)
}
+4
View File
@@ -370,6 +370,7 @@ impl PdfCraftApp {
reload_changed_files: true,
update_check_at_start: true,
at_exit: None,
startup_time: None,
show_secured_notice: true,
text_links: true,
always_default_view: false,
@@ -747,6 +748,9 @@ impl eframe::App for PdfCraftApp {
let ctx = ui.ctx().clone();
self.guarded_frame(&ctx, |app| app.ui_unguarded(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,
/// Optional host cleanup invoked once in `eframe::App::on_exit` (e.g. Nightly session record).
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
/// settings restrict changes). Off only hides that notice (#4035); kept in the settings.
pub show_secured_notice: bool,
+22
View File
@@ -1,5 +1,27 @@
# 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
On one Windows 11 Pro build 26200 host, the official PdfCraft 0.6.0 x86 installation and