espresso3389 / pdfrx

pdfrx is yet another PDF viewer implementation that built on the top of pdfium. The plugin currently supports Android, iOS, Windows, macOS, Linux, and Web.
MIT License
60 stars 36 forks source link

Large partial image and _cachePageImage while scaling #124

Closed yhyh0 closed 1 month ago

yhyh0 commented 1 month ago

@espresso3389 I saw your changes on implementing the partial image. That is amazing, thank you!

I played with it a bit, still seeing a 1.8-2.5GB memory usage when zooming a 3000x2000 pdf page into a 4.5 scale value. I can see a _cachePageImage goes up to 8403x11885 in size for a scale value of 4.149, which might be still too large, and could be the main reason of high mem usage. I've also found a const globalScale = 300.0 / 72.0 line in the viewer, how did you come up with that 300.0 number? Should that be smaller?

yhyh0 commented 1 month ago

or maybe, actually.. we should transform the canvas, instead of upscaling the image. sorry for keep bouncing around ideas..

espresso3389 commented 1 month ago

7ecb2601d4d406cfebc9ed8dae6ac3afd2a454cf introduces onePassRenderingScaleThreshold and its default value is 200/72 (implies rendering at 200-dpi).

yhyh0 commented 1 month ago

Let me close this issue for now, it's already much better especially with your partial image change and pages going away. Next we probably should investigate the lock(making use of multi cores), cache compressed images, etc.

espresso3389 commented 1 month ago

Next we probably should investigate the lock(making use of multi cores), cache compressed images, etc.

It's the restriction of pdfium. pdfium does not support concurrent rendering of pages of a PdfDocument. A possible workaround for the issue is use multiple PdfDocument instances though it doubles/multiplicates the memory usage.