Teknik makale

PDFium: render cache and zoom performance in Delphi

Delphi ve C++Builder uygulamalarına PDFium VCL Component iş akışlarını, Lazarus/FPC projelerine PDFium LCL Component iş akışlarını; görüntüleme, render, formlar, yazdırma, preflight raporları ve standart odaklı doğrulama için kaynak kodlu bileşenlerle ekleyin.

Bu yazı developers building document viewers that must feel responsive on large PDFs and high-DPI displays için hazırlanmıştır. render cache and zoom performance konusunu tek bir bileşen çağrısı olarak değil, üretim düzeyinde belge mühendisliği olarak ele alır.

Pratik risk şudur: zooming can appear fast in a sample but stutter under large pages, thumbnails, annotations, continuous scrolling, or memory pressure. Bu nedenle akışın yazılı sözleşmeye, gözlemlenebilir tanılara ve gerçekçi regresyon dosyalarına ihtiyacı vardır.

Mimari kararlar

Define cache policy as viewer behavior. cache key fields such as page, zoom, rotation, DPI, color mode, and annotation state / memory budget, eviction strategy, thumbnail sharing, and prefetch distance

  • cache key fields such as page, zoom, rotation, DPI, color mode, and annotation state
  • memory budget, eviction strategy, thumbnail sharing, and prefetch distance
  • progressive rendering behavior for fast preview versus final-quality output
  • cancellation rules when users scroll, resize, search, or change zoom quickly

Uygulama akışı

Measure the interaction path, not only render time. Aşağıdaki sıra, iş akışını Delphi ve C++Builder ekipleri için incelenebilir tutar.

  1. record render requests through one queue instead of direct control event handlers
  2. reuse cached bitmaps only when the key fully matches the visible state
  3. render low-latency placeholders before high-quality pages when appropriate
  4. cancel stale jobs and evict pages outside the viewport and prefetch window
  5. measure frame latency and memory during realistic scroll and zoom sequences

Doğrulama kanıtı

Performance evidence users can feel. Bu alanları çıktı veya destek kaydıyla birlikte saklayın.

  • cache hit rate, render latency, queue depth, cancellation count, and memory peak
  • viewport size, zoom level, DPI, page dimensions, and color-filter state
  • time to first preview and time to final-quality render
  • eviction and prefetch behavior during continuous scrolling

Caching is a user-experience feature

A render cache should balance page quality, memory budget, cancellation, invalidation, and perceived latency. The viewer needs to cancel stale work when the user scrolls or zooms rather than finishing irrelevant renders.

Profile ownership and versioning

A named, versioned profile is easier to review than options scattered across forms, scripts, and batch parameters. It also makes support reports readable when customers use older templates or policies.

  • cache key fields such as page, zoom, rotation, DPI, color mode, and annotation state
  • memory budget, eviction strategy, thumbnail sharing, and prefetch distance
  • progressive rendering behavior for fast preview versus final-quality output
  • cancellation rules when users scroll, resize, search, or change zoom quickly
  • cache hit rate, render latency, queue depth, cancellation count, and memory peak
  • viewport size, zoom level, DPI, page dimensions, and color-filter state

Mühendislik inceleme notları: render cache and zoom performance

Özelliğin bir demoyu aşıp sürüm, destek ve müşteri eskalasyonu sırasında savunulabilir olduğunu doğrulamak için bu inceleme notlarını kullanın.

  • Karar: cache key fields such as page, zoom, rotation, DPI, color mode, and annotation state. Uygulama baskı noktası: reuse cached bitmaps only when the key fully matches the visible state. Kabul kanıtı: time to first preview and time to final-quality render. Regresyon tetikleyicisi: rendering thumbnails and pages through separate caches wastes memory
  • Karar: memory budget, eviction strategy, thumbnail sharing, and prefetch distance. Uygulama baskı noktası: render low-latency placeholders before high-quality pages when appropriate. Kabul kanıtı: eviction and prefetch behavior during continuous scrolling. Regresyon tetikleyicisi: large engineering drawings can exceed cache assumptions made for letters or invoices
  • Karar: progressive rendering behavior for fast preview versus final-quality output. Uygulama baskı noktası: cancel stale jobs and evict pages outside the viewport and prefetch window. Kabul kanıtı: cache hit rate, render latency, queue depth, cancellation count, and memory peak. Regresyon tetikleyicisi: annotation overlays invalidate cached pages when review state changes
  • Karar: cancellation rules when users scroll, resize, search, or change zoom quickly. Uygulama baskı noktası: measure frame latency and memory during realistic scroll and zoom sequences. Kabul kanıtı: viewport size, zoom level, DPI, page dimensions, and color-filter state. Regresyon tetikleyicisi: high-DPI displays multiply bitmap memory even when page count is small
  • Karar: cache key fields such as page, zoom, rotation, DPI, color mode, and annotation state. Uygulama baskı noktası: record render requests through one queue instead of direct control event handlers. Kabul kanıtı: time to first preview and time to final-quality render. Regresyon tetikleyicisi: rendering thumbnails and pages through separate caches wastes memory
  • Karar: memory budget, eviction strategy, thumbnail sharing, and prefetch distance. Uygulama baskı noktası: reuse cached bitmaps only when the key fully matches the visible state. Kabul kanıtı: eviction and prefetch behavior during continuous scrolling. Regresyon tetikleyicisi: large engineering drawings can exceed cache assumptions made for letters or invoices
  • Karar: progressive rendering behavior for fast preview versus final-quality output. Uygulama baskı noktası: render low-latency placeholders before high-quality pages when appropriate. Kabul kanıtı: cache hit rate, render latency, queue depth, cancellation count, and memory peak. Regresyon tetikleyicisi: annotation overlays invalidate cached pages when review state changes

Sınır durumları

  • large engineering drawings can exceed cache assumptions made for letters or invoices
  • annotation overlays invalidate cached pages when review state changes
  • high-DPI displays multiply bitmap memory even when page count is small
  • rendering thumbnails and pages through separate caches wastes memory

Delphi / C++Builder notes

PDFium Component should sit behind a small service boundary that receives files, streams, profiles, and credentials, then returns output paths, warnings, metrics, and validation status. Important terms include render cache, zoom, DPI, progressive rendering, eviction, prefetch.

Delphi kod örneği

Aşağıdaki Delphi taslağı bu konu için pratik bir servis sınırını gösterir. Politika kontrollerini, günlüklemeyi ve doğrulamayı dar ürün çağrısı bölümünün dışında tutarak akışı test edilebilir bırakın.

procedure TPreviewForm.RenderCachedPage(PageIndex: Integer; Zoom: Double);
var
  CacheKey: string;
begin
  CacheKey := Format('%d:%.2f', [PageIndex, Zoom]);
  if not FRenderCache.TryGetValue(CacheKey, FPageBitmap) then
  begin
    FPageBitmap := PdfView.RenderPage(PageIndex, 0, Round(850 * Zoom), Round(1100 * Zoom), ro0, []);
    FRenderCache.Add(CacheKey, FPageBitmap);
  end;
  PaintBitmap(FPageBitmap);
end;

Üretim kontrol listesi

  • İş akışını boş bir dosyada, normal bir müşteri dosyasında ve en kötü durum dosyasında çalıştırın
  • Oluşturulan PDF'yi hedef görüntüleyici, doğrulayıcı, yazıcı veya aşağı akış uygulamasıyla açın
  • Ürün sürümünü, profil sürümünü, giriş karmasını, çıktı yolunu, geçen süreyi ve uyarı sayısını kaydedin
  • Parolaları, sertifikaları, geçici dosyaları ve müşteri verilerini açık saklama kuralları altında tutun
  • Bir müşteri dosyası yeni bir uç durum ortaya çıkardığında regresyon belgeleri ekleyin

Ürün belgeleri

PDFium Component

Ek kod örnekleri

procedure TViewerForm.RequestRender(TargetZoom: Single);
var
  Status: TPdfProgressiveStatus;
begin
  if FTokenSource <> nil then
    FTokenSource.Cancel;           // abandon the previous in-flight render
  FTokenSource := TPdfCancellationTokenSource.New;  // FPdfAsync unit

  Status := Pdf.RenderPageProgressive(FBackBuffer, 0, 0,
    FBackBuffer.Width, FBackBuffer.Height, FTokenSource.Token,
    ro0, [reAnnotations]);

  case Status of
    prsDone:      PresentBackBuffer;
    prsCancelled: ;                // superseded by a newer request: drop silently
    prsFailed:    ShowRenderFailure;
  end;
end;