Performance impact of using decorators
Terry Reedy
tjreedy at udel.edu
Fri Mar 10 12:25:50 EST 2006
"vinjvinj" <vinjvinj at gmail.com> wrote in message
news:1142003515.886709.290360 at j33g2000cwa.googlegroups.com...
> 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?
As Alex said, perhaps. A decorator that would not result in a runtime call
would be one that, for example, registers the function somewhere and
returns it unchanged and unwrapped. @expose and @partOfTabUI both seem
like they might do something like that.
IF the overhead becomes a problem, and if you use the same stack (or parts
of a stack) of decorators for multiple functions, then you could write a
few decorators that combine multiple actions with one call.
Terry Jan Reedy
More information about the Python-list
mailing list