[ 
https://issues.apache.org/jira/browse/PDFBOX-5996?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Tilman Hausherr updated PDFBOX-5996:
------------------------------------
    Affects Version/s: 3.0.4 PDFBox
                       2.0.34

> 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
>            Priority: Minor
>         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

Reply via email to