Skip to content

Commit

Permalink
Improve performance of deflate Z_FULL_FLUSH
Browse files Browse the repository at this point in the history
When using deflate Z_FULL_FLUSH all output data is flushed out on a
byte boundary. The dictionary is discarded, such that the next blocks
can be decoded without upfront history.

We missed to set the DDCB flag preventing the dictionary to be
transfered up again. This caused situations where we wanted to encode
e.g. 32 KiB data using Z_FULL_FLUSH, and transfered output data and
addionally 32 KiB dictionary data, which got immediately discarded.

A potential problem might occur if not all output bytes can be
written. In this case we still need the dictionary. So it is best to
provide a large enough output buffer to avoid that situations.
  • Loading branch information
fhaverkamp committed Nov 5, 2015
1 parent 64579b7 commit 7b32d99
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions lib/deflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -735,8 +735,8 @@ int zedc_deflate(zedc_streamp strm, int flush)
tries = 1;

if ((strm->flags & ZEDC_FLG_SKIP_LAST_DICT) &&
(flush == ZEDC_FINISH) && (strm->avail_out >= strm->avail_in)) {
//static int count = 0;
(((flush == ZEDC_FINISH) || (flush == ZEDC_FULL_FLUSH)) &&
(strm->avail_out >= strm->avail_in))) {

out_dict = asiv->out_dict;
out_dict_len = asiv->out_dict_len;
Expand All @@ -745,11 +745,6 @@ int zedc_deflate(zedc_streamp strm, int flush)
asiv->out_dict = 0x0;
asiv->out_dict_len = 0x0;
tries = 2;

//if (count++ < 2)
// fprintf(stderr, "[%s] Try to optimize dict transfer: "
// "avail_in=%d avail_out=%d\n", __func__,
// strm->avail_in, strm->avail_out);
}

for (i = 0; i < tries; i++) {
Expand Down Expand Up @@ -782,8 +777,8 @@ int zedc_deflate(zedc_streamp strm, int flush)

/* What a pitty, need to repeat to get back dictionary */
if ((strm->flags & ZEDC_FLG_SKIP_LAST_DICT) &&
(flush == ZEDC_FINISH) &&
(strm->avail_out >= strm->avail_in)) {
(((flush == ZEDC_FINISH) || (flush == ZEDC_FULL_FLUSH)) &&
(strm->avail_out >= strm->avail_in))) {
cmd->cmdopts |= DDCB_OPT_DEFL_SAVE_DICT;
asiv->out_dict = out_dict;
asiv->out_dict_len = out_dict_len;
Expand Down

0 comments on commit 7b32d99

Please sign in to comment.