# HG changeset patch # User Gregory Szorc # Date 1476576653 25200 # Node ID 9626022feaa4733da7e1fff2465d7da0665539bf # Parent 9f41b66cffc0adbe23fc14652ac28948c444da13 bundle2: only emit compressed chunks if they have data This is similar to 58467204cac0. Not all calls into the compressor return compressed data, as the compressor may buffer compressed output internally. It is cheaper to check for empty chunks than to send empty chunks through the generator. When generating a gzip-v2 bundle of the mozilla-unified repo, this change results in 50,093 empty chunks not being sent through the generator (out of 1,902,996 total input chunks). diff -r 9f41b66cffc0 -r 9626022feaa4 mercurial/bundle2.py --- a/mercurial/bundle2.py Sat Oct 15 15:01:14 2016 -0700 +++ b/mercurial/bundle2.py Sat Oct 15 17:10:53 2016 -0700 @@ -573,7 +573,9 @@ yield param # starting compression for chunk in self._getcorechunk(): - yield self._compressor.compress(chunk) + data = self._compressor.compress(chunk) + if data: + yield data yield self._compressor.flush() def _paramchunk(self): @@ -1324,7 +1326,9 @@ def chunkiter(): yield header for chunk in subchunkiter: - yield z.compress(chunk) + data = z.compress(chunk) + if data: + yield data yield z.flush() chunkiter = chunkiter()