Optimizing Large Document Rendering in ASP.NET Core
← Back to Blog2 min read

Optimizing Large Document Rendering in ASP.NET Core

Speed is a Feature

When a user clicks "View Document", they expect it to load instantly. Whether it's a 3-page memo or a 5,000-page legal brief, waiting is not an option. Doconut is engineered for speed, but for enterprise-scale workloads, optimizing your implementation is key.

1. Smart Caching Strategies

Repeatedly rendering the same page is a waste of CPU cycles. Doconut's built-in caching interface allows you to store rendered page images efficiently.

  • Disk Caching: Great for single-server setups with fast NVMe storage. Rendered pages are saved to App_Data and served statically on subsequent requests.
  • Distributed Caching (Redis): Essential for load-balanced farms. If Server A renders Page 5, Server B should be able to serve it without re-rendering. Doconut supports custom ICache implementations to plug directly into Redis or Memcached.
// Example: Implementing a simple caching strategy
viewer.Cache = new Doconut.Cache.DiskCache(@"C:\CachePath");
// or configure Redis

2. Lazy Loading & Virtualization

Never send the whole document at once. Doconut uses a virtualized scrolling approach.

  • Only the visible pages (plus a small buffer) are requested from the server.
  • As the user scrolls, new pages are fetched on-demand. This ensures that opening a 100MB PDF takes roughly the same initial load time as a 1MB file.

3. Concurrency & Threading

In ASP.NET Core, resource management is crucial.

  • Parallel Processing: Doconut can utilize multi-core CPUs to pre-render adjacent pages while the user is reading the current one.
  • Token Management: Close document handles (objDoc.Close()) immediately when they are no longer needed (or use using blocks) to keep memory footprint low.

4. Format-Specific Optimizations

  • PDFs: Ensure "Fast Web View" (Linearization) isn't strictly necessary for Doconut (since we render on server), but optimized internal structures help.
  • Images: For huge TIFFs/JPEGs, enabling Doconut's tiled rendering can prevent OutOfMemory exceptions by processing the image in chunks.

Scaling Up

For applications serving thousands of concurrent users, Doconut is stateless-ready. By abstracting the storage (S3/Azure Blob) and the cache (Redis), you can scale your compute instances horizontally (Kubernetes/App Service Plan) to handle any traffic spike.

Deliver lightning-fast document viewing with a tuned Doconut implementation.

#Performance#ASP.NET Core#Caching#Optimization#Scalability