From: Chuck E. <ec...@mi...> - 2000-12-06 16:25:27
|
At 06:16 AM 12/6/2000 +0000, Tripp Lilley wrote: >Second: are class / static attributes more costly to retrieve than >instance attributes? This one is one that's particularly dear to me right >now, since I'm trying to wrap my head around some sick foolishness for my >own project (Selfish - <http:sourceforge.net/projects/selfish/> ). Anyway, >when "pool" is an attribute of SitePage (the class, not the instance), >this means that the interpreter first looks in the instance, then in the >class (then inheritance, etc.), right? I guess that stuff's all done in >fastish C, anyway, so it's not really that critical. self.foo is two dictionary look ups. One for the local 'self' and one for 'foo' in self. someGlobalModule.foo is three: a failed one in the locals, one in the globals and one in the module. However, I find that Python's C-based hash-based searching for identifiers is so much faster than Python byte code that it doesn't matter. In a benchmark I was able to achieve a 1.5% slowdown by inflating the look ups to 5 levels. And this was a program with no networking or database (e.g., total CPU and very much not like our typical apps). Also, it occurred to me that in the __init__.py of the context (e.g., the directory that WebKit points to), you could just do this: import DBPool DBPool.Pool = DBPool.DBPool(args) In order to create this once per site. Now, no one has to check if this was already created. >Finally, a real, live, Webware question :) Does WW instantiate a new >SitePage instance for each hit? The answer to that, of course, will inform >how trivial or important my first question (about "if SitePage.pool...") >is :) No, instances are reused (unless you override canBeReused() to return 0). You can end up with multiple instances if there are concurrent requests. You can check out WebKit's internal servlet cache by going to something like: http://127.0.0.1/WebKit.cgi/Admin/ServletCacheByPath This will tell you the number instances created for each one. -Chuck |