[MERGE] Improve decorators when necessary

Martin Pool mbp at canonical.com
Thu Jan 25 00:00:32 GMT 2007


On 24 Jan 2007, John Arbash Meinel <john at arbash-meinel.com> wrote:
> The attached patch includes the new form of decorators into bzrlib. And
> then it disables them from the 'bzr' command script. This means that
> running 'bzr' will still be fast, but if you use an interactive
> interpreter, or it is imported from elsewhere (like by epydoc) you will
> get the nice looking documentation.
> 
> In testing the difference is 300ms for bzr --version with the new
> decorators versus 270ms without them. So the fact that they add 30ms to
> startup time is significant, and worth the effort of avoiding it.

Very nice.

> -def needs_read_lock(unbound):
> +
> +def _get_parameters(func):
> +    """Recreate the parameters for a function using introspection.
> +
> +    :return: (function_params, passed_params)
> +        function_params is the list of parameters to the original function.
> +        This is something like "a, b, c=None, d=1"
> +        passed_params is how you would pass the parameters to a new function.
> +        This is something like "a=a, b=b, c=c, d=d"
> +    """

When I first read the docstring, it was not clear to me that you were
returning strings containing python source code, rather than a
structured representation.

> +    global _inspect
> +    if _inspect is None:
> +        import inspect
> +        _inspect = inspect

Is this to avoid the overhead of running the import statement each time
this method is entered?

+1

-- 
Martin



More information about the bazaar mailing list