Skip to content

Commit 0273f80

Browse files
art804DutchSailor
andauthored
fix(open): skip the cold-open pre-render until the worker pool is ready (#302)
The page-1 pre-render fired on every file-association launch; with the PDFium worker pool still spawning at boot it fell back to an in-process parse in the main process, concurrent with PDF.js parsing the same bytes - on large documents the doubled peak takes the load down, so double-clicked large files failed while File > Open (warm pool) worked. Gate the pre-render on a new worker_pool_ready command; the normal render path is unaffected. Co-authored-by: Maarten Vroegindeweij <30430941+DutchSailor@users.noreply.github.com>
1 parent 335f9dc commit 0273f80

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

open-pdf-studio/js/pdf/loader.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,17 @@ export async function loadPDF(filePath, docIndex, preloadedData = null) {
240240
if (_skipPre) console.log('[prog-guard] zware pagina → cold-open pre-render overgeslagen');
241241
} catch {}
242242
}
243+
// The pre-render is an optimisation, not a requirement: when the PDFium
244+
// worker pool hasn't finished spawning (cold start via file association),
245+
// it would fall back to an in-process parse in the main process while
246+
// PDF.js parses the same bytes — on large documents that doubles peak
247+
// memory during boot and can take the whole load down. Skip it then.
248+
let _poolReady = false;
243249
if (filePath && isTauri() && !_skipPre) {
250+
try { _poolReady = await invoke('worker_pool_ready'); } catch { _poolReady = false; }
251+
if (!_poolReady) console.log('[prog-guard] worker pool not ready → cold-open pre-render skipped');
252+
}
253+
if (filePath && isTauri() && !_skipPre && _poolReady) {
244254
const { renderPdfPage: _renderPdfPage } = await import('./engine-router.js');
245255
_renderPdfPage({
246256
path: filePath,

open-pdf-studio/src-tauri/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,6 +1574,18 @@ fn render_pdf_page_skia(
15741574
Ok(tauri::ipc::Response::new(out))
15751575
}
15761576

1577+
/// Whether the PDFium worker pool has finished spawning. Lets the frontend
1578+
/// skip optional work (e.g. the cold-open pre-render) that would otherwise
1579+
/// fall back to an in-process PDFium parse in the main process — on a large
1580+
/// document that fallback runs concurrently with the PDF.js parse of the
1581+
/// same bytes and can take the whole load down at startup.
1582+
#[tauri::command]
1583+
fn worker_pool_ready(
1584+
pool: tauri::State<'_, std::sync::Arc<tokio::sync::OnceCell<worker_pool::WorkerPool>>>,
1585+
) -> bool {
1586+
pool.get().is_some()
1587+
}
1588+
15771589
#[tauri::command]
15781590
async fn render_pdf_page(
15791591
path: String,
@@ -2562,6 +2574,7 @@ pub fn run(opts: StartupOpts) {
25622574
uninstall_plugin,
25632575
read_plugin_file,
25642576
render_pdf_page,
2577+
worker_pool_ready,
25652578
render_pdf_page_region,
25662579
render_tile_scene_region,
25672580
page_content_size,

0 commit comments

Comments
 (0)