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

Add pledgeinsize #64

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Add pledgeinsize #64

wants to merge 10 commits into from

Conversation

nhz2
Copy link
Member

@nhz2 nhz2 commented Sep 7, 2024

This is part of JuliaIO/TranscodingStreams.jl#239

This PR reduces the allocations needed when decompressing data compressed with transcode.

For example:

julia> using BenchmarkTools

julia> using CodecZstd

julia> c = transcode(ZstdCompressor, rand(UInt8, 10000));

julia> @btime transcode($(ZstdDecompressor()), $(c));

With this PR and JuliaIO/TranscodingStreams.jl#239:
416.579 ns (4 allocations: 10.05 KiB)

Before:
510.451 ns (5 allocations: 19.72 KiB)

Copy link

codecov bot commented Sep 7, 2024

Codecov Report

Attention: Patch coverage is 94.11765% with 1 line in your changes missing coverage. Please review.

Project coverage is 63.56%. Comparing base (7bd48b4) to head (055af7b).

Files with missing lines Patch % Lines
src/libzstd.jl 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #64      +/-   ##
==========================================
+ Coverage   61.35%   63.56%   +2.21%     
==========================================
  Files           5        5              
  Lines         370      376       +6     
==========================================
+ Hits          227      239      +12     
+ Misses        143      137       -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nhz2 nhz2 marked this pull request as draft October 5, 2024 16:04
@nhz2 nhz2 marked this pull request as ready for review October 5, 2024 18:26
@@ -31,6 +31,7 @@ jobs:
Pkg.Registry.update()
Pkg.activate(;temp=true)
# force it to use this PR's version of the package
ENV["JULIA_PKG_DEVDIR"]= mktempdir()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ensures fresh versions of the developed packages, in case this is run locally.

end

function TranscodingStreams.process(codec::ZstdCompressor, input::Memory, output::Memory, error::Error)
if codec.cstream.ptr == C_NULL
error("startproc must be called before process")
Base.error("`startproc` must be called before `process`")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error is the name of a local variable, so I need to specify Base.error here.

src/compression.jl Outdated Show resolved Hide resolved
s = TranscodingStream(codec(), sink; stop_on_end=true)
write(s, b"Hello")
close(s)
buffer3 = take!(sink)
@test CodecZstd.find_decompressed_size(buffer3) == CodecZstd.ZSTD_CONTENTSIZE_UNKNOWN
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transcode with ZstdCompressor now records the decompressed size.

@nhz2 nhz2 requested a review from mkitti October 5, 2024 19:44
Copy link
Member

@mkitti mkitti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Julia functions should not return error codes. They should throw exceptions.

src/libzstd.jl Show resolved Hide resolved
src/compression.jl Outdated Show resolved Hide resolved
src/compression.jl Outdated Show resolved Hide resolved
@nhz2 nhz2 marked this pull request as draft October 6, 2024 00:28
@nhz2 nhz2 marked this pull request as ready for review October 6, 2024 19:11
@nhz2 nhz2 requested a review from mkitti October 6, 2024 19: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