title: Why is getattr() so much slower than self.__dict__.get()?
body: <p>The example below is from a REST database driver on Python 2.7.</p>
  
  <p>In the <code>__setattr__</code> method below, if I use the commented out <code>getattr()</code> line, it reduces the object instantiation performance from 600 rps to 230. </p>
  
  <p>Why is <code>getattr()</code> so much slower than <code>self.__dict__.get()</code> in this case?</p>
  
  <pre><code>class Element(object):
  
      def __init__(self, client):
          self._client = client
          self._data = {}
          self._initialized = True
  
      def __setattr__(self, key, value):
          #_initialized = getattr(self, "_initialized", False)
          _initialized = self.__dict__.get("_initialized", False)
          if key in self.__dict__ or _initialized is False:
              # set the attribute normally
              object.__setattr__(self, key, value)
          else:
              # set the attribute as a data property
              self._data[key] = value
  </code></pre>