Performance improvements to EoD SQL 2.0

Having released EoD SQL 2.0, I thought I should take another look at the performance of the new code. Although the API does run a lot faster once you have a Query object in memory, constructing the Query in the first place is not as fast as the EoD SQL 1.0 branch. There are two reasons for this:

  1. EoD SQL 1.0 Lazy-Loaded all of the method implementations (and in fact almost all of the data)
    1. Although faster to construct an object, the actual execution was much slower
    2. EoD SQL 2.0 eager builds as much data as possible
    3. EoD SQL 2.0 also works with tighter bindings under the hood than EoD SQL 1.0 did
      1. Takes the guess work out of turning a row into an object
  2. EoD SQL 1.0 Cached it’s implementation objects and reused them extensively
    1. EoD SQL 2.0’s close bindings makes it much harder to cache the data for re-use
    2. However, much of the data is very lightweight to construct

With these two factors in mind, I climbed into the code and added an internal cache structure (the first part of EoD SQL 2.1). The new cache is very different to those used in EoD SQL 1.0:

  • The new cache doesn’t store actual bindings, but rather all the data required to create a binding
    • Once a method is called, the implementation will store the resulting binding for that Query instance forever
    • Thus caching is not as useful, especiall since two different methods can’t share bindings anymore
  • The new cache makes use of SoftReferences instead of being a permanent cache
    • Follows the caching technique used by java.lang.reflect
    • If you create static references to your Queries, the cache can be garbage collected
    • If you manage your Connections by hand, the parts of the cache that are in more use will stick around

This change marks the first part of EoD SQL 2.1, the new code is in Subversion if you want to try it out for yourself.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: