# HG changeset patch # User Bryan O'Sullivan # Date 1347649537 25200 # Node ID 6d97dd630d79d143c4cb8d38a785b442fa1766cd # Parent 39c6e349dfff0c8bc85fbee43ba22bd466c4037c wireproto: bypass filechunkiter for small files when streaming Merely creating and using a generator has a measurable impact, particularly since the common case for stream_out is generators that yield just once. Avoiding generators improves stream_out performance by about 7%. diff -r 39c6e349dfff -r 6d97dd630d79 mercurial/wireproto.py --- a/mercurial/wireproto.py Fri Sep 14 12:05:12 2012 -0700 +++ b/mercurial/wireproto.py Fri Sep 14 12:05:37 2012 -0700 @@ -555,8 +555,11 @@ repo.ui.debug('sending %s (%d bytes)\n' % (name, size)) # partially encode name over the wire for backwards compat yield '%s\0%d\n' % (store.encodedir(name), size) - for chunk in util.filechunkiter(sopener(name), limit=size): - yield chunk + if size <= 65536: + yield sopener(name).read(size) + else: + for chunk in util.filechunkiter(sopener(name), limit=size): + yield chunk finally: sopener.mustaudit = oldaudit diff -r 39c6e349dfff -r 6d97dd630d79 tests/test-check-code-hg.t --- a/tests/test-check-code-hg.t Fri Sep 14 12:05:12 2012 -0700 +++ b/tests/test-check-code-hg.t Fri Sep 14 12:05:37 2012 -0700 @@ -6,6 +6,10 @@ > exit 80 > fi $ hg manifest | xargs "$check_code" || echo 'FAILURE IS NOT AN OPTION!!!' + mercurial/wireproto.py:560: + > yield sopener(name).read(size) + use opener.read() instead + FAILURE IS NOT AN OPTION!!! $ hg manifest | xargs "$check_code" --warnings --nolineno --per-file=0 || true hgext/convert/cvsps.py:0: @@ -159,6 +163,9 @@ mercurial/commands.py:0: > ui.write('symlink: %s\n' % (util.checklink(path) and 'yes' or 'no')) warning: unwrapped ui message + mercurial/wireproto.py:0: + > yield sopener(name).read(size) + use opener.read() instead tests/autodiff.py:0: > ui.write('data lost for: %s\n' % fn) warning: unwrapped ui message