Friday, December 31, 2010

Speeding up pages in App Engine - Part 2

So you've got AppStats configured and you've sped up some page loading times by removing obviously unnecessary queries and gets.  Also by using prefetch_refprops from Speeding up pages in App Engine - Part 1 you've removed the staircase of gets.  Now what?

In my case I realized that one of my Models was no longer needed.  I was storing DOSRecurr objects (which contain a reference to DOS object which in turn contain a reference to ClientInfo objects) in the datastore.  Fetching objects from the datastore is slow so if you can avoid looking into the datastore, your pages will be loaded faster.

In my case, I realized I was having to calculate all of the DOSRecurr objects every time anyway, since if a DOS changed then my DOSRecurr might have changed as well.  So I kept the same DOSRecurr model, but instead of storing it in the database, I just created them every time and then threw them away afterwards.

By keeping the DOSRecurr model I was able to keep all the logic and implementation that used the DOSRecurr model but by no longer storing it in the datastore I sped up my application significantly.

The main take away from this lesson is:
Don't store and fetch things from the App Engine Datastore if you don't have to!