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

Use dynamic huffman tables to reduse the crate size. #35

Merged
merged 1 commit into from
Jan 13, 2018
Merged

Use dynamic huffman tables to reduse the crate size. #35

merged 1 commit into from
Jan 13, 2018

Conversation

RazrFalcon
Copy link
Contributor

This commit makes this crate 4x times smaller without performance changes.

Sizes from the image-png crate:

Before:

% cargo bloat --release --example pngcheck --filter inflate
 File  .text     Size Name
10.4%  70.7% 506.2KiB [1307 Others]
 4.2%  28.7% 205.3KiB inflate::InflateStream::next_state
 0.0%   0.3%   2.0KiB inflate::DynHuffman16::new
 0.0%   0.1%   1.0KiB inflate::InflateStream::run_len_dist
 0.0%   0.1%     508B inflate::DynHuffman16::read
 0.0%   0.1%     475B inflate::InflateStream::update
 0.0%   0.0%     201B inflate::InflateStream::from_zlib
14.7% 100.0% 715.7KiB .text section size, the file size is 4.8MiB

After:

% cargo bloat --release --example pngcheck --filter inflate
 File  .text     Size Name
10.7%  91.0% 506.2KiB [1307 Others]
 1.0%   8.2%  45.9KiB inflate::InflateStream::next_state
 0.0%   0.4%   2.0KiB inflate::DynHuffman16::new
 0.0%   0.2%   1.0KiB inflate::InflateStream::run_len_dist
 0.0%   0.1%     508B inflate::DynHuffman16::read
 0.0%   0.1%     475B inflate::InflateStream::update
 0.0%   0.0%     201B inflate::InflateStream::from_zlib
11.8% 100.0% 556.3KiB .text section size, the file size is 4.6MiB

Benchmark results using libflate/flate_bench:

Before:
-                 inflate: elapsed=1.903052s, size=288632530
After:
-                 inflate: elapsed=1.869871s, size=288632530

@RazrFalcon
Copy link
Contributor Author

Looks like the build is failed due to ? operator. Should I use try!?

@eddyb
Copy link
Member

eddyb commented Jan 13, 2018

@RazrFalcon Yeah, I think so.

src/lib.rs Outdated
5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5
]));
Copy link
Member

Choose a reason for hiding this comment

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

Actually, you should .unwrap(), sorry - these can't ever fail, they're effectively constants.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But why it returns 'Result' then?

Copy link
Member

Choose a reason for hiding this comment

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

I meant these calls can't ever fail because they have constant arguments - for other inputs, those functions may return Err.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eddyb done.

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