comparison mercurial/revlog.py @ 27475:a2e2a8fa5fd1

revlog: avoid string slice when decompressing u* chunks Revlog chunks can be stored uncompressed. If the first byte of the raw data is \0, we store the data as is. Else we prefix it with 'u'. Before, we performed a string slice to strip out the 'u' prefix. With this patch, we use a buffer to avoid an extra memory copy and associated garbage collection overhead. I was unable to verify any performance impact of this patch. For both mozilla-central and the hg repos, the number of manifest revisions with 'u' prefixes is very small - under 1%. So this change likely isn't called enough to have an impact on manifest reading. However, the reasoning behind this change is solid, so it should be safe.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 20 Dec 2015 16:00:27 -0800
parents 3dea4eae4eeb
children b502138f5faa
comparison
equal deleted inserted replaced
27474:e517a89c24e1 27475:a2e2a8fa5fd1
108 try: 108 try:
109 return _decompress(bin) 109 return _decompress(bin)
110 except zlib.error as e: 110 except zlib.error as e:
111 raise RevlogError(_("revlog decompress error: %s") % str(e)) 111 raise RevlogError(_("revlog decompress error: %s") % str(e))
112 if t == 'u': 112 if t == 'u':
113 return bin[1:] 113 return util.buffer(bin, 1)
114 raise RevlogError(_("unknown compression type %r") % t) 114 raise RevlogError(_("unknown compression type %r") % t)
115 115
116 # index v0: 116 # index v0:
117 # 4 bytes: offset 117 # 4 bytes: offset
118 # 4 bytes: compressed length 118 # 4 bytes: compressed length