title: GAE NDB performance of ComputedProperty versus on-demand lookup of related-model count
body: <p>Using Google App Engine, I am just curious if anyone can illuminate the performance characteristics (reading &amp; writing) of using a <code>ComputedProperty</code> versus calculating-on-demand a count of a related model.</p>
  
  <p>A ComputedProperty has the distinct benefit of allowing indexing on a property, but I am just curious about how fast reading &amp; writing are in comparison.</p>
  
  <p>For example, given two models:</p>
  
  <pre><code>class Car(ndb.Model):
    owner_key = ndb.KeyProperty(kind='Owner', indexed=True)
  
  class Owner(ndb.Model)
     def cars_count(self):
         ndb.query(Car.owner_key == self.key).count()
  
     cars_count_prop = ndb.ComputedProperty(cars_count)
  </code></pre>
  
  <p>The question really breaks down into something like the following:</p>
  
  <ol>
  <li>how much slower is writing <code>Owner</code> because it has the <code>cars_count_prop</code>?</li>
  <li>how much faster is reading <code>cars_count_prop</code> than <code>cars_count</code>?</li>
  </ol>
  
  <p>Or, in other words:</p>
  
  <ol>
  <li>what is the asymptotic computational complexity (big-O) of reading and writing each?</li>
  <li>what is the average case computational complexity - for people other than <a href="http://www.jaylenosgarage.com/" rel="nofollow">Jay Leno</a> (i.e. small numbers of <code>Car</code> instances per <code>Owner</code>)?</li>
  <li>How much of the wait for reading and writing is computational complexity, and how much is database / memcache lookups?</li>
  </ol>