~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-20 22:12:00 UTC
  • mto: This revision was merged to the branch mainline in revision 3644.
  • Revision ID: john@arbash-meinel.com-20080820221200-1pnk090rjwbydavn
Start working on an alternate way to track compressed_chunk state.
I tried doing a copy() before flush() but that is quite expensive.
Both because it now does copy() but it also does a bigger flush.
Next I'll try tracking 2 objects.

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
        self.unused_bytes = None
65
65
        self.reserved_size = reserved
66
66
        self.min_compress_size = self._default_min_compression_size
 
67
        self.num_zsync = 0
67
68
 
68
69
    def finish(self):
69
70
        """Finish the chunk.
107
108
        If the bytes fit, False is returned. Otherwise True is returned
108
109
        and the bytes have not been added to the chunk.
109
110
        """
 
111
        # TODO: lsprof claims that we spend 0.4/10s in calls to write just to
 
112
        #       thunk over to _write. We don't seem to need write_reserved
 
113
        #       unless we have blooms, so this *might* be worth removing
110
114
        return self._write(bytes, False)
111
115
 
112
116
    def write_reserved(self, bytes):
128
132
        if (next_seen_size < self.min_compress_size * capacity):
129
133
            # No need, we assume this will "just fit"
130
134
            out = self.compressor.compress(bytes)
 
135
            if out:
 
136
                self.bytes_list.append(out)
131
137
            self.bytes_in.append(bytes)
132
138
            self.seen_bytes = next_seen_size
133
 
            if out:
134
 
                self.bytes_list.append(out)
135
139
        else:
136
140
            if not reserved and self.num_repack >= self._max_repack:
137
141
                # We have packed too many times already.
143
147
            out = self.compressor.flush(Z_SYNC_FLUSH)
144
148
            if out:
145
149
                self.bytes_list.append(out)
 
150
            self.num_zsync += 1
146
151
            # TODO: We may want to cache total_len, as the 'sum' call seems to
147
152
            #       be showing up a bit on lsprof output
148
153
            total_len = sum(map(len, self.bytes_list))
160
165
                    self.compressor = compressor
161
166
                    self.bytes_list = bytes_out
162
167
                    self.unused_bytes = bytes
 
168
                    self.num_zsync = 0
163
169
                    return True
164
170
                else:
165
171
                    # This fits when we pack it tighter, so use the new packing
166
172
                    self.compressor = compressor
167
173
                    self.bytes_in.append(bytes)
168
174
                    self.bytes_list = bytes_out
 
175
                    # There is one Z_SYNC_FLUSH call in
 
176
                    # _recompress_all_bytes_in
 
177
                    self.num_zsync = 1
169
178
            else:
170
179
                # It fit, so mark it added
171
180
                self.bytes_in.append(bytes)