Performance impact of using decorators

Alex Martelli aleaxit at yahoo.com
Fri Mar 10 16:24:26 CET 2006


vinjvinj <vinjvinj at gmail.com> wrote:

> I'm building an application with cherrypy and have started using
> decorators quite extensively. A lot of my exposed functions look like:
> 
> @expose
> @startTransactrionAndBuildPage
> @partOfTabUi(tabId)
> @convert(arg1=int, arg2=str)
> def do_main_page(self, arg1, arg2):
>    some code
> 
> I've become really fond of decorators and use them quite a lot. I've
> also ready that function calls are expensive in python. In the above
> example, does the interpreter call 5 different functions?

At def-execution time, presumably 6 (the two decorators w/o args, plus 2
each for those w/args); at call time, it depends what the decorators are
doing (if each adds exactly one wrapping closure, for example, there
will indeed be 5 nested calls). Unfortunately I do not know much of
today's cherrypy internals, so I don't know what each decorator is doing
internally.


Alex
 



More information about the Python-list mailing list