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

Improve buffering in Compression Streams API #2469

Merged
merged 4 commits into from
Jul 31, 2024
Merged

Conversation

fhanau
Copy link
Collaborator

@fhanau fhanau commented Jul 31, 2024

  • Eliminate recursion in compression streams writeInternal()
    This avoids having large stack traces when compressing larger chunks of data
    and is easier to maintain with the added comments.

  • Reduce excessive copying in Compression Streams API
    In the Compression Streams API, introduce a helper class to only shift output
    data when this would reduce output vector size significantly. This results in
    the leading bytes of the output vector becoming invalid when reading only parts
    of it, which requires careful tracking but avoids having to move the output data
    with every read from the buffer.

  • Increase Compression Streams output buffer size
    Since zlib uses 256KiB of memory per compression stream with default settings, a
    size of 16KiB will not increase memory usage by a large proportion. This should
    make processing data slightly faster. Ideally we'd want this to be larger than
    deflate's 32KiB window size which would allow zlib to avoid some extra copying
    during decompression, but that can be done at a later time alongside other
    compression optimizations.

  • Clean up ArrayPtr casts

This avoids having large stack traces when compressing larger chunks of data
and is easier to maintain with the added comments.
@fhanau fhanau requested review from mikea and jasnell July 31, 2024 17:40
@fhanau fhanau requested review from a team as code owners July 31, 2024 17:40
@fhanau fhanau force-pushed the felix/compression-streams branch from 3e38ad7 to 59eb30a Compare July 31, 2024 18:08
In the Compression Streams API, introduce a helper class to only shift output
data when this would reduce output vector size significantly. This results in
the leading bytes of the output vector becoming invalid when reading only parts
of it, which requires careful tracking but avoids having to move the output data
with every read from the buffer.
Since zlib uses 256KiB of memory per compression stream with default settings, a
size of 16KiB will not increase memory usage by a large proportion. This should
make processing data slightly faster. Ideally we'd want this to be larger than
deflate's 32KiB window size which would allow zlib to avoid some extra copying
during decompression, but that can be done at a later time alongside other
compression optimizations.
@fhanau fhanau force-pushed the felix/compression-streams branch from 59eb30a to eea2cf2 Compare July 31, 2024 21:54
@fhanau fhanau merged commit ec3dcac into main Jul 31, 2024
9 checks passed
@fhanau fhanau deleted the felix/compression-streams branch July 31, 2024 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants