[ https://issues.apache.org/jira/browse/PDFBOX-5996?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17947766#comment-17947766 ]
ASF subversion and git services commented on PDFBOX-5996: --------------------------------------------------------- Commit 1925306 from Tilman Hausherr in branch 'pdfbox/branches/3.0' [ https://svn.apache.org/r1925306 ] PDFBOX-5996: Set size for ByteArrayOutputStreams, as suggested by Axel Howind > set size for ByteArrayOutputStreams > ----------------------------------- > > Key: PDFBOX-5996 > URL: https://issues.apache.org/jira/browse/PDFBOX-5996 > Project: PDFBox > Issue Type: Improvement > Affects Versions: 2.0.34, 3.0.4 PDFBox > Reporter: Axel Howind > Assignee: Tilman Hausherr > Priority: Minor > Fix For: 2.0.35, 3.0.5 PDFBox, 4.0.0 > > Attachments: > set_initial_sizes_for_ByteArrayOutputStreams_set_initial_sizes_for_ByteArrayOutputStreams.patch > > > PDFBox and FontBox use ByteArrayOutputstream instances in many places. The > standard JDK implementation initializes the size with 32 bytes. If the > capacity needs to be increased, the increases the buffer size, usually by > reallocating a buffer twice the current size and copying the internal array > to the new buffer. > I have checked different places in the code and found many instances where > either the correct size is known beforehand and can be set when creating the > instance (this is the case for many instantiations in the PDFFont and > COSString classes). Setting the exact size avoids reallocations when the used > size will exceed the default size of 32 bytes. > In other places, at least a lower bound is known and can be used as initial > size. > Please try the patches. I did not run benchmarks, but (together with another > patch I am preparing) the times to run the test target decreased noticeably > on my machine. -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org For additional commands, e-mail: dev-h...@pdfbox.apache.org