[MERGE] Improve decorators when necessary

John Arbash Meinel john at arbash-meinel.com
Thu Jan 25 15:54:34 GMT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

John Arbash Meinel wrote:
> Martin Pool wrote:

...

>>>> +    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?
> 
> That was the thought. I have a few options:
> 
> 1) 'import inspect' at the top. The problem is inspect is one of the
> files we *don't* want if we can help it. (Hence the
> 'inspect_for_copy.py'  that I wrote).
> 
> 2) lazy_import('import inspect'). That requires making decorators depend
> on lazy_import. And I was trying to keep dependencies minimal. This
> would certainly be an alternative, though.
> 
> 3) 'import inspect' inside the function. I thought we found that to be a
> significant overhead.


Well, after doing some testing, I decided to just simplify it to (3).
Because it isn't being run during the critical startup path (only during
- --lsprof, or with the interpreter). And it makes the code cleaner, which
is a big benefit.

I will add a comment why it is in local scope, so someone doesn't try to
pull it out to global scope.

Also, I couldn't find a huge performance difference, probably 100 calls
to 'import inspect' is not a huge deal. Where it was a big deal was when
we were iterating over revisions, or something where we were doing it
thousands of times.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFuNK6JdeBCYSNAAMRAlJsAJwIJQD6DE4iBAY1xx4WsYnFnTc0WACeMord
XdnYCO12NAllfEkOQsYMsXg=
=dW/6
-----END PGP SIGNATURE-----



More information about the bazaar mailing list