I'm trying to optimize some Python code. The profiler tells me that SQLAlchemy's _get_col() is what's killing performance. The code looks something like this:
lots_of_rows = get_lots_of_rows()
for row in lots_of_rows:
if row.x == row.y:
print row.z
I was about to go through the code and make it more like this...
lots_of_rows = get_lots_of_rows()
for row in lots_of_rows:
if row[0] == row[1]:
print row[2]
...but I've found some documentation that seems to indicate that when accessing row objects like arrays, you're actually still pulling dictionary keys. In other words, the row object looks like this:
'x': (x object)
'0': (x object)
'y': (y object)
'1': (y object)
'z': (z object)
'2': (z object)
If that's the case, I doubt I'll see any performance improvement from accessing columns by number rather than name. Is there any way to get SA to return results as a list of tuples, or a list of lists, rather than a list of dictionaries? Alternately, can anyone suggest any other optimizations?