Michael Bayer wrote:
another question -

why exactly is ProxyEngine a hack ? if it were called "Schema", and had a "connect" method, would that make it less of a hack ?


I was referring to the logic in ProxyEngine/BaseProxyEngine.__getattr__ and how 
inefficient that was on every engine attribute lookup. Every call does extra 
attribute lookups, which can get quite expensive in a tight inner loop. Here's 
an expanded version of __getattr__:

def __getattr__(self, attr): --> initial lookup (proxyEngine.<attr>) (cost 1)
  e = self.get_engine() --> single lookup (cost 1)

  # begin expanded method call: self.get_engine()
  if self.storage.engine is None: <-- double lookup (cost 2)
      raise AttributeError('No connection established')
  return self.storage.engine <-- double lookup (cost 2)
  # end expanded method call

  # resume __getattr__
  if e is not None:
      return getattr(e, attr) <-- final lookup (cost 1)
  raise AttributeError('No connection established in ProxyEngine: '

That's 7 dictionary lookups when only one is necessary. Granted, dictionary 
lookups are cheap, but this has an odor.


No, changing the name and adding an extra method would not change anything...unless that 
extra method returned the "real" engine (with no proxy wrapped around it) on 
which all SQL queries would be executed. This connect() method would be executed once per 
Query call (i.e. one time for every query.select(...)).

All these extra lookups do not seem worth it to me when you look at what a 
ProxyEngine does before it's connected to a real engine (hardly anything).  
Does it have to be this way? I guess it's also doing thread-local stuff in 
there, but why do we need thread-local on ProxyEngine? It's easy enough to add 
a thread-local proxy if it's needed, but not worth the extra cost if it's not 
needed.

~ Daniel



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to