I'm doing some processing with fonts  and I have noticed that the ResourceCache 
seems really slow if the jvm works with more memory: processing with 500 Mb of 
max heap size is faster (1 min 30s) than using 1500 Mb (2 min).

Adding the following parameter to the jvm: -XX:SoftRefLRUPolicyMSPerMB=1 
improves a lot the performance (1min for 500 Mb of heap and 43s for 1500 Mb of 
heap) but I have noticed that with more complex files and processing the issue 
still appears (i.e:  performance is better with less memory) and sometimes I 
get an "OutOfMemory" exception (which doesn't happen if I completely disable 
the cache).

Steps to reproduce: get TestResourceCache.java and manyfonts.pdf from here: 
https://gofile.io/d/Lrcg4v and run:

java -Xmx1500m -cp 
"pdfbox-2.0.21.jar;commons-logging-1.2.jar;fontbox-2.0.21.jar;." 
TestResourceCache manyfonts.pdf

If you want to disable ResourceCache:
java -Xmx1500m -cp 
"pdfbox-2.0.21.jar;commons-logging-1.2.jar;fontbox-2.0.21.jar;." 
TestResourceCache manyfonts.pdf -n

And using the XX:SoftRefLRUPolicyMSPerMB flag:
java -Xmx1500m -XX:SoftRefLRUPolicyMSPerMB=1 -cp 
"pdfbox-2.0.21.jar;commons-logging-1.2.jar;fontbox-2.0.21.jar;." 
TestResourceCache manyfonts.pdf

If you disable the  ResourceCache then processing takes about 35 secs. In this 
case I can simply disable the cache, but most of the time the cache gives 
better performance, so, I would like to keep it.

I have tested in Windows and Linux environments and with the previous version 
of pdfbox. Results are the same.

About the parameter -XX:SoftRefLRUPolicyMSPerMB: 
https://bugs.java.com/bugdatabase/view_bug.do;jsessionid=8a08ffe78680b155d0cc88c63d76?bug_id=6835406

Esteban Ruiz

Reply via email to