~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tuned_gzip.py

  • Committer: Matt Nordhoff
  • Date: 2009-04-04 02:50:01 UTC
  • mfrom: (4253 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4256.
  • Revision ID: mnordhoff@mattnordhoff.com-20090404025001-z1403k0tatmc8l91
Merge bzr.dev, fixing conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
 
18
18
"""Bzrlib specific gzip tunings. We plan to feed these to the upstream gzip."""
19
19
 
114
114
        """A tuned version of gzip._write_gzip_header
115
115
 
116
116
        We have some extra constrains that plain Gzip does not.
117
 
        1) We want to write the whole blob at once. rather than multiple 
 
117
        1) We want to write the whole blob at once. rather than multiple
118
118
           calls to fileobj.write().
119
119
        2) We never have a filename
120
120
        3) We don't care about the time
136
136
 
137
137
    def _read(self, size=1024):
138
138
        # various optimisations:
139
 
        # reduces lsprof count from 2500 to 
 
139
        # reduces lsprof count from 2500 to
140
140
        # 8337 calls in 1272, 365 internal
141
141
        if self.fileobj is None:
142
142
            raise EOFError, "Reached EOF"
207
207
        """tuned to reduce function calls and eliminate file seeking:
208
208
        pass 1:
209
209
        reduces lsprof count from 800 to 288
210
 
        4168 in 296 
 
210
        4168 in 296
211
211
        avoid U32 call by using struct format L
212
212
        4168 in 200
213
213
        """
214
 
        # We've read to the end of the file, so we should have 8 bytes of 
 
214
        # We've read to the end of the file, so we should have 8 bytes of
215
215
        # unused data in the decompressor. If we don't, there is a corrupt file.
216
216
        # We use these 8 bytes to calculate the CRC and the recorded file size.
217
217
        # We then check the that the computed CRC and size of the
228
228
 
229
229
    def _read_gzip_header(self, bytes=None):
230
230
        """Supply bytes if the minimum header size is already read.
231
 
        
 
231
 
232
232
        :param bytes: 10 bytes of header data.
233
233
        """
234
234
        """starting cost: 300 in 3998
271
271
 
272
272
    def readline(self, size=-1):
273
273
        """Tuned to remove buffer length calls in _unread and...
274
 
        
 
274
 
275
275
        also removes multiple len(c) calls, inlines _unread,
276
276
        total savings - lsprof 5800 to 5300
277
277
        phase 2:
281
281
        leading to a drop to:
282
282
        4168 calls in 1977
283
283
        4168 call to read() in 1646
284
 
        - i.e. just reduced the function call overhead. May be worth 
 
284
        - i.e. just reduced the function call overhead. May be worth
285
285
          keeping.
286
286
        """
287
287
        if size < 0: size = sys.maxint
329
329
        # to :
330
330
        # 4168 calls in 417.
331
331
        # Negative numbers result in reading all the lines
332
 
        
 
332
 
333
333
        # python's gzip routine uses sizehint. This is a more efficient way
334
334
        # than python uses to honor it. But it is even more efficient to
335
335
        # just read the entire thing and use cStringIO to split into lines.
342
342
 
343
343
    def _unread(self, buf, len_buf=None):
344
344
        """tuned to remove unneeded len calls.
345
 
        
 
345
 
346
346
        because this is such an inner routine in readline, and readline is
347
347
        in many inner loops, this has been inlined into readline().
348
348
 
349
349
        The len_buf parameter combined with the reduction in len calls dropped
350
 
        the lsprof ms count for this routine on my test data from 800 to 200 - 
 
350
        the lsprof ms count for this routine on my test data from 800 to 200 -
351
351
        a 75% saving.
352
352
        """
353
353
        if len_buf is None:
371
371
            self.offset += data_len
372
372
 
373
373
    def writelines(self, lines):
374
 
        # profiling indicated a significant overhead 
 
374
        # profiling indicated a significant overhead
375
375
        # calling write for each line.
376
376
        # this batch call is a lot faster :).
377
377
        # (4 seconds to 1 seconds for the sample upgrades I was testing).