Open Bug 1005005 Opened 6 years ago Updated 2 years ago

pdf.js causes memory use to spike by 2Gb

Categories

(Firefox :: PDF Viewer, defect, P3)

defect

Tracking

()

People

(Reporter: Yoric, Unassigned)

References

(Blocks 1 open bug, )

Details

(Whiteboard: [pdfjs-c-performance])

(reported using the contribute form)

STR:
1. Open http://tarifs.lessentiel.lu/docs/TARIFS2014_IMPRESSION.pdf
2. Watch about:memory 

Result: Memory increases by 2+Gb.
Priority: -- → P3
Whiteboard: [pdfjs-c-performance]
With a version of pdf.js from early January, I was able to get RSS up to about 2,200 MiB.

With a development version, I haven't managed to get RSS to get higher than 700 MiB, and speed is much better.

It's still pretty slow, though. The newspaper thumbnails on pages 7 and 8 in particular are a real stress test. The time is mostly due to the text layer -- page 8 has almost 12,000 text divs! -- so bug 1054161 will help.
Here's the operator histogram for pages 7 and 8:

> (  1)    29072 (17.7%, 17.7%): showText
> (  2)    27439 (16.7%, 34.5%): moveText
> (  3)    22853 (13.9%, 48.4%): setWordSpacing
> (  4)    22812 (13.9%, 62.3%): setCharSpacing
> (  5)     9927 ( 6.1%, 68.4%): restore
> (  6)     9927 ( 6.1%, 74.4%): save
> (  7)     7332 ( 4.5%, 78.9%): transform
> (  8)     6605 ( 4.0%, 82.9%): constructPath

There are *many* sequences like this:

> setCharSpacing: [0.004]
> setWordSpacing: [-0.004]
> moveText:       [1.222,0]
> showText:       [[{"fontChar":"u","unicode":"u","accent":null,"width":630},{"fontChar":"l","unicode":"l","accent":null,"width":315}]]
> setCharSpacing: [0]
> setWordSpacing: [0]
> moveText:       [0.947,0]
> showText:       [[{"fontChar":",","unicode":",","accent":null,"width":278}]]
> setCharSpacing: [0.003]
> setWordSpacing: [-0.003]
> moveText:       [0.686,0]
> showText:       [[{"fontChar":"1","unicode":"1","accent":null,"width":556},{"fontChar":"6","unicode":"6","accent":null,"width":556}]]
> moveText:       [1.55,0]
> showText:       [[{"fontChar":"a","unicode":"a","accent":null,"width":556},{"fontChar":"n","unicode":"n","accent":null,"width":648}]]

Two glyphs per |showText| is typical (and also explains why there are so many text layer divs).

AFAICT, a lot of these |setWordSpacing| ops are useless because they only have an effect if there is a null glyph (representing a word space) present in a |showText| before the next |setWordSpacing|. But |setWordSpacing| is not an expensive op, so it might not be worth trying to remove them.
I'm tempted to close this bug report. Memory usage, while still high, is 3x better than it was when the bug was reported. Thoughts?
You need to log in before you can comment on or make changes to this bug.