[PATCH 04 of 10] wireproto: bypass filechunkiter for small files when streaming

Mads Kiilerich mads at kiilerich.com
Thu Sep 13 17:06:12 CDT 2012


Bryan O'Sullivan wrote, On 09/13/2012 09:01 PM:
> # HG changeset patch
> # User Bryan O'Sullivan <bryano at fb.com>
> # Date 1347562629 25200
> # Node ID 8a634678f1ddf810c61b66752b732e69abd265e8
> # Parent  f85d5c5b428594aeccc4ce0a81786f53eea9039c
> 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 --git a/mercurial/wireproto.py b/mercurial/wireproto.py
> --- a/mercurial/wireproto.py
> +++ b/mercurial/wireproto.py
> @@ -556,8 +556,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 --git a/tests/test-check-code-hg.t b/tests/test-check-code-hg.t
> --- a/tests/test-check-code-hg.t
> +++ b/tests/test-check-code-hg.t
> @@ -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!!!

Failure _is_ not an option. (The test should perhaps complain harder.)

/Mads


More information about the Mercurial-devel mailing list