Last week I noticed a couple of classes of optimizations in our calendar
drawing code that apply in general to all of our UI.

The first case is where we can save wxPython calls by rearranging the
order in which we draw things on the screen. I noticed this in the
calendar background drawing code which basically did:

for line in lines:
  if line is full hour:
    wx.SetPen(hourPen)
    wx.DrawLine()
  elif line is half hour:
    wx.SetPen(halfHourPen)
    wx.DrawLine()

The above pseudo code draws the calendar background lines from top to
bottom in order, and changes the pen for every other line (hour and half
hour lines are drawn with different pen). However, we can do the above
with just two calls to SetPen:

wx.SetPen(hourPen)
for line in lines:
  if line is full hour:
    wx.DrawLine()

wx.SetPen(halfHourPen)
for line in lines:
  if line is half hour:
    wx.DrawLine()

This is a win for two reasons. First, SetPen is expensive (at least when
compared to not calling it at all;). Second, crossing the Python -
wxWidgets boundary is expensive, so the fewer times you need to cross it
the better.


The second case is that wxPython has wx.DC.Draw*List methods. Which
means that the above cases came out like this:

dc.DrawLineList(hourLines, hourPen)
dc.DrawLineList(halfHourLines, halfHourPen)


I made a few of these changes, but there are many more cases where these
techniques can be applied to our code base.

-- 
  Heikki Toivonen


Attachment: signature.asc
Description: OpenPGP digital signature

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Open Source Applications Foundation "chandler-dev" mailing list
http://lists.osafoundation.org/mailman/listinfo/chandler-dev

Reply via email to