On the printing slowness of Postscript produced by the JVM from calls to Graphics.drawString() (Linux/Unix)

Happy new year,
before the holidays my attention was drawn to an issue that supposedly the Postscript produced by the JVM is too big and hence too slow.  Here are my findings.
The issue
Text printing via CUPS to native Postscript printers can be slow. Printing a terms and conditions page (17000 characters/page) takes three and a half minutes to print on a Dell 2330 dn laser printer (96 MB,Max speed 33 ppm). The file is about 8 MB in size. To contrast that, rendering the text to a buffered image with 300 DPI and printing the result produces 7 MB of output which prints in 30 seconds on the same printer. More measures for different printers and documents can be found at the end of this post. The issues is registered as  "JDK-4627340 : RFE: A way to improve text printing performance for postscript devices" (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4627340) and the proposed workaround is to use printer fonts.
Side remark regarding the workaround
There is a regression that prevents the workaround from working (bug 9008662 at Sun (not yet visible),  bug 8023990 at OpenJDK (https://bugs.openjdk.java.net/browse/JDK-8023990). Without knowing what other bad side effects this might have, the issue can be resolved by setting the property "sun.awt.fontconfig". On my system I set it to the location of a "fontconfig.properties" of a JVM that does not have the bug (e.g. /home/alex/openjdk_7_b147_jun_11/openjdk/build/linux-i586/bin/java -Dsun.awt.fontconfig="/etc/java-6-openjdk/fontconfig.properties" Print2DtoStream). I also successfully tested the workaround on an Oracle JVM 1.7.0_03-b04.
Back to the main topic
How the JVM draws text if it can't use a standard printer font
Text is drawn with postscript path drawning commands such as "moveto", "lineto" or "curveto". As an example consider the word "ll" which looks something like this:
%N->short for "newpath"
N
%paint first "l"
%M->short for "moveto"
0.76875 11.06 M
%L->short for "lineto"
0.76875 2.468 L
1.823 2.468 L
1.823 11.06 L
0.76875 11.06 L
%p->short for "closepath"
P
%paint second "l"
3.649 11.06 M
3.649 2.468 L
4.703 2.468 L
4.703 11.06 L
3.649 11.06 L
P
The same text could be printed with a printer font using the command "(ll) show" which is much more compact but is available in Java only for the Postscript standard fonts and it isn't working at all right now as explained above.
Is it the file size?
My first thought was that the file size was the source of of slowness and so I wrote a small processor that would detect glyphs, normalize*1 them and place them in a dictionary. Recurring references to the same glyph were replaced by a dictionary reference  (This is incidentally the fix proposed by the original author of RFE 4627340). This shrunk the file to about 11% of the original size but the processing time surprisingly doubled.
*1: With "normalizing" I mean applying a translation transform so that the smallest coordinates in the contours of a glyph are exactly 0. In addition I experimented with performing a normalizing scale transform so that all coordinates lie between 0 and 1 so that identical glyphs are detected at arbitrary positions and at different font sizes.
That led to the question to why there is such a big difference in performance between a Type 1 font dictionary and a self constructed dictionary since both contain basically the same drawing instructions. The difference is apparently that fonts are cached and user drawings are not unless explicitly told.
The Postscript "ucache" instruction
Postscript level 2 introduces the "ucache" instruction which seems to be defined for precisely this kind of problem. From the documentation:
"Some PostScript programs define paths that are repeated many times. To optimize the interpretation of such paths, the PostScript language provides a facility called the user path cache. This cache, analogous to the font cache, retains the results from previously interpreted user path definitions. When the PostScript interpreter encounters a user path that is already in the cache, it substitutes the cached results instead of reinterpreting the path definition. "
After adding "ucache" instructions to my filter the speed improved by factor 10.
To illustrate the said the "ll" text from above looked as follows after the transformation:
%definition of the glyph "l" named "p0"
/p0
ucache
0.000 0.000 1.054 8.592 setbbox
0.000 8.592 moveto
0.000 0.000 lineto
1.054 0.000 lineto
1.054 8.592 lineto
0.000 8.592 lineto
closepath
} cvlit def
G
N
0.769 2.468 translate
%draw "l" at 0.769 2.468
p0 ufill
-0.769 -2.468 translate
3.649 2.468 translate
%draw "l" at 3.649 2.468
p0 ufill
-3.649 -2.468 translate
For ucached shapes there is a special compact representation so that the same can be written as follows:
/p0
0.000 0.000 1.054 8.592
0.000 8.592
0.000 0.000
1.054 0.000
1.054 8.592
0.000 8.592
} cvlit def
G
N
0.769 2.468 translate
p0 ufill
-0.769 -2.468 translate
3.649 2.468 translate
p0 ufill
-3.649 -2.468 translate
Interestingly the speed improvement remained the same on a Chinese report that had hardly any character reuse. Upon this observation I changed the filter to not use a dictionary but so simply instruct the interpreter to cache each glyph definition and the performance remained nearly the same.
The initial "ll" text from above looks as follows after this transformation:
N
%paint first "l" cached
0.76875 2.468 1.823 11.06
0.76875 11.06
0.76875 2.468
1.823 2.468
1.823 11.06
0.76875 11.06
} ufill
%paint second  "l" cached
3.649 2.468 4.703 11.06
3.649 11.06
3.649 2.468
4.703 2.468
4.703 11.06
3.649 11.06
} ufill
Note that I didn't normalize the shapes.
Why does this improve the performance so vastly if the shape is drawn only once? For a while I thought perhaps that the interpreter would consider two paths which differ only by a translation as being the same but rereading the documentation and looking at the Chinese example in which nearly all characters are unique, disproves this. The relevant part of the documentation reads:
"Caching is based on the value of a user path object. That is, two user paths are considered the same for caching purposes if all of their corresponding elements are equal, even if the objects themselves are not.
A user path placed in the cache need not be explicitly retained in virtual memory. An equivalent user path appearing literally later in the program can take advantage of the cached information. Of course, if it is known that a given user path will be used many times, defining it explicitly in VM avoids creating it multiple times.
User path caching, like font caching, is effective across translations of the user coordinate system, but not across other transformations, such as scaling or rotation. In other words, multiple instances of a given user path painted at different places on the page will take advantage of the user path cache when the current transformation matrix has been altered only by translate. If the CTM has been altered by scale or rotate , the instances will be treated as if they were described by different user paths."
An explanation that would fit the findings
The rasterizer renders the page multiple time (perhaps in order to save memory and produce horizontal strips). On the first rendering the cache is filled and reused on the subsequent renderings thereby improving performance even if all cached items are used only once.
Based upon this theory I hoped that the strip height would grow if I added more memory to the printer but this was not the case on the two printers for which I had memory to test with. Even substantial changes to the available memory (e.g. going from 32 MB to 96 MB) had no impact whatsoever on the performance.
Summary
The issue is not related to the file size as the original requester suspected but very likely due to the uncached rendering. Caching of glyphs can be achieved by using the "ucache" instruction or perhaps by placing the glyphs in font dictionaries and using the "show" operator.
Although reported in 2003, time is apparently not healing this quick enough since printers in the 10,000$ class like the Sharp MX2310U still take a full minute to print 10 pages and a desktop printer may be blocked for over an hour for the same document.
We will now try to use the CUPS filter and leave the printers configured as Postscript printers. If there is interest I can post the single file source of a CUPS filter that performs the inline conversion described. Apart from libl it requires no additional libraries and written using flex it is reasonably lightweight and fast.
I would appreciate any opinion on whether or not the proposed workaround for bug 8023990 (https://bugs.openjdk.java.net/browse/JDK-8023990), namely having the system property "sun.awt.fontconfig" pointing to a working fontconfig.properties of a previously installed and working 1.6 version file, is safe.
Measures (Appendix)
"Terms and Conditions" report
Testing a single page "Terms and Conditions" report in "Arial" 8pt (I am aware that "Helvetica" is width compatible and nearly looks the same but in this particular case the line height was also relevant and as explained above, printer fonts are currently not working). The page contains 17000 characters of which some parts are bold and some italic. This is a real world example and to make things worse the requirement is to print the text on the backside of every page on a certain class of reports. I am aware that this is a bit extreme but I also felt that I couldn't dismiss it as being unreasonable.
File "Arial.ps" (7.5 MB Unmodified output of the JVM)
Printer
Printing time
Dell 2330dn 32MB/96MB
3:50 minutes
Lexmark X658de (55 ppm, aprox. 5,000$)
  1:45 minutes
HP LaserJet 4240n 64 MB
1:12 minutes
Kyocera Taskalfa 300ci (30 PPM, aprox. 8,000$)
1 minute
HP Color LaserJet 4650 dn 128/384MB
51 seconds
Sharp MX 2310U 512MB (55ppm,  aprox. 10,000$)
31 seconds
Arial_inline.ps (8 MB contains "ucache" without normalization and without dictionary)
Printer
Printing time
32MB/96MB
30seconds/30seconds (Improvement by factor 7.7)
Lexmark X658de (55 ppm, aprox. 5,000$)
  15 seconds (Improvement by factor 7)
HP LaserJet 4240n 64 MB
47 seconds (Improvement by factor 1.5)
Kyocera Taskalfa 300ci (30 PPM, aprox. 8,000$)
20 seconds (Improvement by factor 5)
HP Color LaserJet 4650 dn 128/384MB
46 seconds (Improvement by factor 1.1)
Sharp MX 2310U 512MB (55ppm,  aprox. 10,000$)
14 seconds (Improvement by factor 2)
Asian characters test
Testing 10 pages of Asian characters in the font "WenQuanYi Zen Hei" 12pt where each page contains 49 lines by 40 unique characters. The document contains the 30,000 characters between unicode 0x4e00 and 0x9fff. This is a nonsense stress test but it illustrates  that the "ucache" speedup works even though no character is repeated in the report.
Asian.ps  (52 MB Unmodified output of the JVM)
Printer
Printing time
Dell 2330dn 32MB/96MB
64 minutes
Lexmark X658de (55 ppm, aprox. 5,000$)
Not measured
HP LaserJet 4240n 64 MB
11 minutes
Kyocera Taskalfa 300ci (30 PPM, aprox. 8,000$)
Not measured
HP Color LaserJet 4650 dn 128/384MB
9:13 minutes
Sharp MX 2310U 512MB (55ppm,  aprox. 10,000$)
4:08 minutes
Asian_inline.ps (54 MB contains "ucache" without normalization and without dictionary)
Printer
Printing time
32MB/96MB
5:30 minutes (Improvement by factor 11.6)
Lexmark X658de (55 ppm, aprox. 5,000$)
Not measured
HP LaserJet 4240n 64 MB
3:48 minutes (Improvement by factor 2.9)
Kyocera Taskalfa 300ci (30 PPM, aprox. 8,000$)
Not measured
HP Color LaserJet 4650 dn 128/384MB
2:46 minutes (Improvement by factor 3.4)
Sharp MX 2310U 512MB (55ppm,  aprox. 10,000$)
48 seconds (Improvement by factor 5)

Hi Sven,
Will putting the boilerplate in the trailer section allow me to still have it appearing on the back page of the main report? This is where it needs to be as far as the printed report goes - it is duplexed.
Regards
Lanny

Similar Messages

  • I just bought a new printer for my iMac version 10.7 but I am able to install the software but for some reason I am not able to view the printer under system preferences to add the printer. It is connected with the USB cord!!

    I just bought a new printer for my iMac version 10.7 Lion but I am able to install the software but for some reason I am not able to view the printer under system preferences to add the printer. It is connected with the USB cord!! It as if the printer does not show up in the add printer section under system prefernces!!

    I checked the manufacturer and apple site to see if my printer is supprted and it said it was!! I am using the HP officedeskjet 4500 G510a-f (HP Officejet 4500 Desktop)!! Still does not show up under add printers please help!!

  • HT4356 I got a new wireless modem. The HP 8600 no longer works and is not seen as an airport printer. The diagnostics on the printer say it is connected to the wireless.

    Suddenly no wireless printing works. The printer is a HP 8600e and the wireless is turned on and the printer itself can connect to the network, but OSX no longer sees it as an airport printer and nothing prints. I've tried all the Apple support docs without success.

    An old addage of troubleshooting is "First, fix what you most recently changed."
    All the driver uninstall etc, was probably unnecessary.
    Power cycle the router (wireless modem).
    Power cycle the printer.
    Now check that the printer is in the local subnet of the router.
    (local subnet means router is something like 192.168.1.1, your computer is something like 192.168.1.2, and the printer is something like 192.168.1.3 - only the last part - 192.168.1.x - is allowed to be different).
    Add the printer using the default printer browser window.
    If this doesn't work, Reset Printing system and re-add.
    http://support.apple.com/kb/PH11143

  • I switched to Apple Mail in the last two months.  When I attempt to print an email message, I get a blank piece of paper.  When I attempt to use the print options suggested in "Mail Help", the program crashes and has to be reopened.  Any ideas?

    I switched to Apple Mail in the last two months.  When I attempt to print an email message, I get a blank piece of paper.  When I attempt to use the print options suggested in "Mail Help", the program crashes and has to be reopened.  Any ideas?

    Which version of Mail are you using as well as which Snow Leopard version you are using? 

  • I can't seems to print using my macbook air with hp series printers. When I plug the printer via usb to my system, the printer was recognized and installed. But when i send a doc for printing, it doesn't print all . Any help?

    i can't seems to print using my macbook air with hp series printers. When I plug the printer via usb to my system, the printer was recognized and installed. But when i send a doc for printing, it doesn't print all . Any help?

    Greetings,
    Here's a direct link to the drivers you need, they should work perfectly for your situation.

  • What is the latest version of Java produced by the Sun?

    Sorry for this simple question.
    What is the latest version of Java produced by the Sun?

    JDK 6 Update 13
    JDK 6 has been made open source.
    https://jdk6.dev.java.net/
    JDK 7 is in development.
    https://jdk7.dev.java.net/
    Edited by: dvohra on Apr 6, 2009 7:30 AM

  • Hi, Might I know that how to setup the printer setting at InDesign CS6 for the Lable print?

    Hi, Might I know that how to setup the printer setting at InDesign CS6 for the Lable print?

    Label printing isn't something you set up in the print dialog in ID. If your print driver has an n-up feature that might work, but in general you need to create pages of labels to fit your sheets in ID, then print. If you are talking about doing a merge of an address list, read about Data Merge in thehelp files.

  • The print icon no longer brings up the print box

    The print icon no longer bring up the print box, which is the box that appears when clicking on "File" "Print". Instead, it brings up a new webpage with an image of what is to print. That is more cumbersome and takes more steps. Even though I can print from that page, I also have to back out of that new page when
    I am done. I am using Windows 8.

    Sorry, that is a new "feature" in Firefox 29.0.
    You could use '''{Ctrl + P}''' to initiate printing and not see the Print Preview window, but beyond that I don't have a solution for you that involves an easy way to revert to the previous action of that button.
    I use an extension named Print / Print Preview that adds a contextual menu entry for both Print and Print Preview. I don't like wasting the toolbar space for a button, when I can print via a context menu item ''(something that was left out of Firefox since the beginning, IMO)''.

  • I want to print an 8 x 10, but the photo does not look like the print preview - it truncates part of the picture

    I am using an HP PSC 2355 printer - and have not had trouble printing before. The 8 x 10 photo does not print like the print preview does - everything elarges when the actual print completes, which truncates all details that need to be printed. Is ther a setting that I should be choosing?

    There is no O or L in my Serial Number, and it starts with one single D, then a set of 3 numbers, 3 letters, 4 times, then 3 letters closing it down. When I check my Final Cut's serial number in the help section of the software, I get the same number. Yet, when I enter it in the site, it says, I have an invalid serial number. So I will call Apple Care. I hope I will be able to talk to a representative in an hour or so. It always takes so long that I grow beard while I wait.

  • How to enable the print & archive button that appear in the smartform outpu

    How to enable the print & archive button that appear in the smartform output.....

    Hi,
    I agree with the details which has been given above, but still if you want to default option 3 "Print & Archive" in drop down, it is possible.
    All you need to do is to set the value of output_options structure field "TDARMOD" as "3" while passing the parameters to dynamic function module of smartform.
    That will select "Print and Archive" in background and display to user.
    Sumit

  • I have an wireless printer and a new wifi router. I have set the printer and iPhone / iPad correctly to the new router but when i try to print it won't recognise the air printer. Help. All was working fine on my old router

    I Have a new wifi router and have set up my iPad / iPhone and wireless printer correctly  to the new router but I can't print from the iPad and iPhone. It keeps saying ' no AirPrint printer found'. Help please!

    Start with the most basic thing that you can try. Unplug the router from power for about 30 seconds, and restart the printer and the iPad and plug the router back into power.

  • Why do I not have access to all the features of my Canon MG5320 printer in all applications which use a printer? The printer has two paper paths. The rear path is used for photo paper and other specialty papers. this is only one "unavailable".

    I have an iMac late 2012 with OSX 10.8.
    The MG5320 has two paper feed paths; one at the rear for photo paper, brochure paper, and other specialty papers and a tray for regular 8½x11 paper. It also can print on CDs and DVDs and has an automatic duplexer. Canon provides a utility for printing on the CDs and DVDs and also for printing photos and other specialty items. This is available in Mac format also. I installed the most recent drivers and utilities.
    I also have a HP IBM Compatible computer on which the above printer as well as an Epson are installed. Every option of each printer is available in every software application that has need for a printer.
    The Mac printer dialog varies from one application to another. The only applications that list the option for selecting paper quality which includes photo paper are Office for Mac, Pages, and Numbers. Not likely that I would be using any of these for photo printing. Auto duplexing, however, is not available here or in any other applications.
    The print dialog in Aperture, Photoshop Elements for Mac, ACDSee for Mac, or iPhoto provide the choice of numerous sizes of paper but no option for paper quality. Therefore, I attempted to use the print utility supplied by Canon and updated by Apple for printing some photos. The photos are selected in this utility. When the print command was given I was shown a message that the printer was being reset. It then began printing a spreadsheet, which was not even open, from the front tray on regular paper in fast draft quality.
    It is essential that the rear feed be available for printing photos. The printer will not accept photo paper from the front tray. The greater proportion of my printing is photos or other specialty items all of which use paper that must be fed from the rear feed.
    An acquaintence who considers himself to be somewhat of a Mac expert insists that the printer options that I require are available and all I need to do is look for them. The print dialog should be clear enough that "looking for options" is not a necessity. Even so, I have dilligently searched every variation of the Mac print dialog on my iMac and only the office type applications named above included anything other than the basic printer functions.
    I have also searched numerous locations online without finding a solution. I did, however, find that printing and printing problems seem to be common with several versions of the Mac OS and Mac computers in general.
    I would appreciate it if someone could provide me with a solution. I have no desire to upgrade my Windows OS to Windows 8 which is perhaps suitable for "smart" phones but not desktop computers. However, because of the printing issue I have temporarily put my iMac aside and reverted to using my PC with Windows Vista.
    Help!!

    This is a user forum I feel you need to deal with Adobe customer services or support chat did not work in you case.

  • The print.print_to_filename option in about:config no longer works in Firefox 10 for Linux

    I have an older linux box with firefox 3, I believe. And, in about:config I can set the option print.print_to_filename to a path then when I print it defaults to the path I want it to save the PDF to. However, on my new box which has FF10.01 such option doesn't exist and creating it doesn't seem to have any effect. Was this removed? It was a great feature. I don't want to have to install and configure cups again as firefox does the job fantastically. Is there a workaround or can this be brought back in the current version?

    The problem exists with https://www.nytimes.com/ so, as a workaround, you can use http://www.nytimes.com/ (not https) or http://nytimes.com where I don't see the problem.
    Related bug report, if anyone wants to keep track, so that they can reset the '''security.mixed_content.block_active_content''' preference, when it's fixed (read [https://bugzilla.mozilla.org/page.cgi?id=etiquette.html Bugzilla Etiquette] before commenting in bug reports):
    *[https://bugzilla.mozilla.org/show_bug.cgi?id=862164 Bug 862164] - https://www.nytimes<!---->.com/ does not render properly because of mixed content blocking

  • I am having problems connecting my imac to a Kodak printer wirelessly. This was previously working fine. The printer states it is connected to the home network but the connection between computer and printer has been lost/ cannot find printer.

    In addition, I contacted kodak support and they wished to take control of my computer in order to rectify the problem. I did not allow this as I was worried about security . Can anyone tell me whether once you allow someone to take control of your computer, then it is a security risk. What protection does my imac provide ? Thanks. 

    I think you can do it on a one time basis, & not allow after that.
    Mac OS X: About the Reset Printing System feature ...
    http://support.apple.com/kb/HT1341?viewlocale=en_US
    10.5/10.6/10.7/10.8 instructions...
    In System Preferences>Fax & Print, Right click or Control+click on the Printers list Sidebar, choose Reset Printing System.
    if you hold option and click the "-" tab it resets the printing system.
    http://www.macosxhints.com/article.php?story=20031215144430486
    Safe Boot from the HD, (holding Shift key down at bootup), run Disk Utility in Applications>Utilities, then highlight your drive, click on Repair Permissions.
    Any devices that previously appeared in your Printer List and Fax List will need to be added again after resetting the printing system.
    Resetting the printing system in Mac OS X 10.5.x+++
        1.    To use the Reset Printing System feature in Mac OS X 10.5.x, follow these steps:
        2.    Choose System Preferences from the Apple menu.
        3.    Choose Print & Fax from the View menu.
        4.    Control-click on list of printers on the left side of the window, then choose "Reset printing system" from the contextual menu. If you don't see a list of printers, Control-click on the text "Click + to add a printer or fax" and select "Reset printing system..." 
   
  As an alternative, if you currently have one or more printers listed, you can Option-click the "-" (Remove printer) button.
    http://support.apple.com/kb/ht1341
    Reboot.

  • I need to supress the printing of a blank page if the total for an AR Statement is 0 or null.

    I have an issue where the XML file for the R03B5001 AR Statement is outputting records with Header information, (name and address), but the total due for the statement is 0.  I have been able to suppress the printing of the header, and detail in my template, but it still generates a single blank page.  How can I suppress the printing of this page?

    Thanks for your answer. Instead of formatting through FireFox, I had to go in and format it via the printer. Duh! Feel stupid not doing this first. If any one else has this problem, I was able to set it up on the printer by going to Printers > Printer Properties > Printer Preferences and set it up. Good luck and thank you for your reply.

Maybe you are looking for

  • Can I run Windows 8.1 using VirtualBox on my Macbook?

    The system requirements for Windows 8.1 says that it needs "Microsoft DirectX 9 graphics device with WDDM driver".  Can I run Windows 8.1 using VirtualBox on my Macbook? It's a late 2009 model with an NVIDIA GeForce 9400M 256 MB graphics card & 2 GB

  • Apache in FMS 4 Developer vs XAMPP Environment for PHP

    1.  Have a Flash Webpage under development designed to permit preview and streaming of FLV video.  Downloaded FMS Developer as a test server on my computer.  Apache 2.2 loads with it with a checkbox option to install it or not. I'm able to stream my

  • BEA Weblogic error......

    I'm running WL 6.1-SP2, petstore 1.1.2 deployathon, oracle 9i. When I start the "StartExampesServer" script this is the error. <Aug 6, 2002 5:54:47 PM CDT> <Notice> <Management> <Loading configuration file .\config\examples\config.xml ...> <Aug 6, 20

  • SPML Webservices

    Hi, i have scenario in my application like need to do provisioning from an external application thrrough SPML webservices. But my USR table has user defined coulmns along with default columns. can i populate those columns with SPML webservices? Can y

  • [HELP] problem of ECHO during record.

    Hello experts, I have used a java code for sound record and playback from one of the threads in this forum. But i am hearing an ECHO while recording as well as playback. That means the echo is getting stored. i'm attaching the code.can u please sugge