I have been working on a file download link, where the file is
generated dynamically in the view code and returned via the mechanisms
outlined in the help for generated PDFs or CSVs. This works fine, but
the performance is staggeringly bad. When I prototyped the file builder
in a vanilla Python script and ran it from the shell, it wrote the file
out to disk in about 3-4 seconds. Simulating the query using the Django
ORM caused it to take almost a full minute to do the same task.

I modified the code to run under hotshot, which had some surprising
results. Basically, what I'm doing is:

for foo in foos.get_iterator():
  # Pack some of the data into a binary buffer

I expected to see 1 call to function_get_iterator, or, at worst, 1 call
for every GET_ITERATOR_CHUNK_SIZE rows. Instead, I'm seeing *3* calls
to function_get_iterator for every row, which I find perplexing. I
intend to dig into this further but I thought perhaps someone who's
been elbow-deep in the ORM could offer some enlightenment, rather than
sending me in there cold turkey.

Reply via email to