~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/chunk_writer.py

  • Committer: John Arbash Meinel
  • Date: 2008-08-22 05:40:12 UTC
  • mto: This revision was merged to the branch mainline in revision 3653.
  • Revision ID: john@arbash-meinel.com-20080822054012-ikrwmq9nm2q4h6q8
(broken, but hopeful) Change the compact logic.
Instead of only paying attention to the total bytes read,
use the fact that we *know* some of that is already compressed well.
So instead, we just pay attention to the bytes that are added since
the last sync. This means we Z_SYNC_FLUSH much less often.
(After syncing, we end up with more room to add without syncing.)
This improves both the time to compress and the final compressed
size. Need to update tests with the new offsets.
Also, we seem to have found a case where using Z_SYNC_FLUSH
in the middle of a stream will actually generate *better*
compression than compressing the whole stream in one pass.
test_too_much_data_does_not_exceed_size triggers this.
It *can* be packed in more than 100 bytes less than the
amount given by a full compress.

Show diffs side-by-side

added added

removed removed

Lines of Context:
177
177
            if out:
178
178
                self.bytes_list.append(out)
179
179
                self.bytes_out_len += len(out)
180
 
 
181
 
            # We are a bit extra conservative, because it seems that you *can*
182
 
            # get better compression with Z_SYNC_FLUSH than a full compress. It
183
 
            # is probably very rare, but we were able to trigger it.
184
 
            if self.bytes_out_len + 100 <= capacity:
 
180
            if self.bytes_out_len + 10 <= capacity:
185
181
                # It fit, so mark it added
186
182
                self.bytes_in.append(bytes)
187
183
                self.seen_bytes += len(bytes)