Skip to content

Commit 4030100

Browse files
committed
perf(thumbnails): fix 3-second pause that blocked thumbnail processor (v1.47.12)
Root cause (CDP-measured): - renderPage() in renderer.js called pauseThumbnails() at the start of every page render (including initial setViewMode after loadPDF). - pauseThumbnails set processorRunning paused for 3000ms with no early-resume signal. - startProcessor added another 250ms initial delay. - Result: first thumbnail appeared ~2.7s after main page was already rendered. Per-thumbnail render cost itself was only ~3ms (Rust hot path) — the wait dominated. Fix: - Shortened pauseThumbnails auto-resume from 3000ms to 500ms safety fallback. - Removed the 250ms initial startProcessor delay (was 250 → 0). - Exported resumeThumbnails() and call it explicitly from renderer.js's vector path after extract_draw_commands + prepareImages complete (both success and catch branches), so thumbnails resume the moment the active page's render is done — not after a fixed timer. Verified via CDP (Vloerverwarming, 4 pages): - Before: time-to-all-thumbs = 2810ms - After: time-to-all-thumbs = 26ms (108× faster) Thumbnail-to-viewport ratio now well under 1×.
1 parent 87160a6 commit 4030100

6 files changed

Lines changed: 88 additions & 11 deletions

File tree

open-pdf-studio/js/pdf/renderer.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { redrawAnnotations, renderAnnotationsForPage } from '../annotations/rend
77
import { ensureAnnotationsForPage, hidePdfABar } from './loader.js';
88
import { updateAllStatus } from '../ui/chrome/status-bar.js';
99
import { hideProperties } from '../ui/panels/properties-panel.js';
10-
import { updateActiveThumbnail, pauseThumbnails } from '../ui/panels/left-panel.js';
10+
import { updateActiveThumbnail, pauseThumbnails, resumeThumbnails } from '../ui/panels/left-panel.js';
1111
import { createSinglePageTextLayer, clearSinglePageTextLayer, createTextLayer, clearTextLayers, createTextLayerFromRust } from '../text/text-layer.js';
1212
import { createSinglePageLinkLayer, clearSinglePageLinkLayer, createLinkLayer, clearLinkLayers } from './link-layer.js';
1313
import { createSinglePageFormLayer, clearSinglePageFormLayer, createFormLayer, clearFormLayers, hideFormFieldsBar } from './form-layer.js';
@@ -285,8 +285,13 @@ export async function renderPage(pageNum) {
285285
_skipBitmapRender = true;
286286
}
287287
}
288+
// Heavy IPC for the active page is done — let the thumbnail processor
289+
// resume immediately instead of waiting out the pause window.
290+
resumeThumbnails();
288291
} catch (e) {
289292
console.warn('[render] Vector mode failed:', e);
293+
// Failure path: still resume so thumbnails don't stay stuck paused.
294+
resumeThumbnails();
290295
}
291296
}
292297

open-pdf-studio/js/ui/panels/left-panel.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,21 +279,39 @@ let _thumbnailPauseTimer = null;
279279
export function pauseThumbnails() {
280280
_thumbnailsPaused = true;
281281
if (_thumbnailPauseTimer) clearTimeout(_thumbnailPauseTimer);
282-
// Auto-resume after 3 seconds of no navigation
282+
// Auto-resume after a short window of no navigation. Was 3000ms — that
283+
// caused thumbnails to sit idle for ~3s after document open because
284+
// renderer.js calls pauseThumbnails() on the very first page render.
285+
// 500ms is enough to coalesce rapid page-up/page-down without making the
286+
// user wait several seconds for thumbnails on initial load.
283287
_thumbnailPauseTimer = setTimeout(() => {
284288
_thumbnailsPaused = false;
285289
_thumbnailPauseTimer = null;
286290
startProcessor();
287-
}, 3000);
291+
}, 500);
288292
}
289293

290-
// Start the thumbnail processor (with short initial delay so the current page
291-
// render gets the Rust backend first; cached thumbnails return instantly so
292-
// 250ms is enough — the previous 2000ms was visibly slow on small docs).
294+
// Resume thumbnail rendering immediately. Called by the page renderer once
295+
// its IPC-heavy work (extract_draw_commands / prepareImages) has finished,
296+
// so thumbnails don't have to wait the full pause window on initial load.
297+
export function resumeThumbnails() {
298+
if (!_thumbnailsPaused) return;
299+
if (_thumbnailPauseTimer) {
300+
clearTimeout(_thumbnailPauseTimer);
301+
_thumbnailPauseTimer = null;
302+
}
303+
_thumbnailsPaused = false;
304+
startProcessor();
305+
}
306+
307+
// Start the thumbnail processor. The previous 250ms delay added a visible
308+
// lag on small documents — once paused-state is honored, the very first
309+
// thumbnail no longer competes with the active-page render, so a tiny
310+
// yield (1 task tick) is enough to let the UI paint the placeholder first.
293311
function startProcessor() {
294312
if (processorRunning) return;
295313
processorRunning = true;
296-
setTimeout(processNextThumbnail, 250);
314+
setTimeout(processNextThumbnail, 0);
297315
}
298316

299317
// Process the next thumbnail (prioritizes visible pages, then active document)

open-pdf-studio/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "open-pdf-studio",
3-
"version": "1.47.11",
3+
"version": "1.47.12",
44
"description": "A free, open-source PDF annotation editor built with Tauri",
55
"scripts": {
66
"dev": "vite",

open-pdf-studio/src-tauri/Cargo.lock

Lines changed: 55 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

open-pdf-studio/src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "open-pdf-studio"
3-
version = "1.47.11"
3+
version = "1.47.12"
44
description = "A free, open-source PDF annotation editor"
55
authors = ["OpenAEC Foundation"]
66
license = "MIT"

open-pdf-studio/src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://schema.tauri.app/config/2",
33
"productName": "Open PDF Studio",
4-
"version": "1.47.11",
4+
"version": "1.47.12",
55
"identifier": "org.openaec.openpdfstudio",
66
"build": {
77
"frontendDist": "../dist",

0 commit comments

Comments
 (0)