Browser Memory Limits

Moving compute from the server to the client shifts the bottleneck from network latency to local RAM. Understanding how V8 handles large ArrayBuffer allocations is critical.

The 2GB V8 Heap Limit

Historically, the V8 engine (powering Chrome, Edge, and Node.js) enforced a strict heap memory limit of ~1.4GB to 2GB depending on the architecture. While modern 64-bit browsers have relaxed this (sometimes allowing up to 4GB), allocating massive contiguous blocks of memory for document parsing remains risky.

When you load a 100MB PDF in uViewDoc, the raw byte stream takes 100MB. Uncompressing the internal streams, mapping font glyphs, and creating the Canvas DOM elements can easily bloat the memory footprint to 500MB+.

Mitigation Strategies

  • Lazy Rendering: We only parse and render the pages currently visible in the viewport (using IntersectionObserver).
  • Canvas Pooling: Instead of creating 500 individual <canvas> elements, we recycle off-screen canvases.
  • Explicit Garbage Collection: When closing a document, we aggressively nullify references to the PDFDocumentProxy to encourage the browser to free memory.
Warning: Mobile Safari

iOS Safari has notoriously strict per-tab memory limits (often terminating tabs that exceed ~300MB). Attempting to load complex architectural blueprints on older iPhones will likely result in a tab crash.