Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow AccessibleByteArrayOutputStream to shrink #346

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Commits on Nov 3, 2023

  1. Allow AccessibleByteArrayOutputStream to shrink

    AccessibleByteArrayOutputStream currently can only grow
    or stay the same size. This could be a problem if it is used for a rare
    large item, but then used only for small items - the buffer would stay
    large forever, consuming memory. Since an application may hold many of
    these buffers via their use particularly in Cipher, the memory impact
    could be significant.
    
    This simple shrinkage algorithm shrinks the buffer if it has been 'too
    large' N times in a row. N starts at 1, and grows exponentially up to a
    limit of 1024 as re-growths are triggered. N starts low to enable
    reacting quickly, but as more growths are observed it increases to avoid
    churn. It is capped to avoid degrading into 'never-shrink' behaviour
    over the long term.
    
    Other ideas were considered, like keeping track of the last N used sizes
    and making decisions based on those values, but this algorithm has a
    tiny footprint (2 ints, could be shorts) and low computation overhead.
    olivergillespie committed Nov 3, 2023
    Configuration menu
    Copy the full SHA
    4ea2de3 View commit details
    Browse the repository at this point in the history

Commits on Nov 9, 2023

  1. Configuration menu
    Copy the full SHA
    d23cfe4 View commit details
    Browse the repository at this point in the history