[reportlab-users] Performance problem for lineplots with many values (with possible solution)

Robin Becker robin at reportlab.com
Wed Jan 30 13:02:00 EST 2013


On 30/01/2013 10:17, Sebastian Messing wrote:

> Hi!

>

> I tried to generate a lineplot with joinedLines=1. The lineplot has three lines,

> each line with 86000 values. The generation of the lineplot is very, very slow

> (hours).

>

> I use ReportLab 2.6 but I also found the problem in ReportLab daily from

> 01/29/2013 in /src/reportlab/graphics/charts/lineplots.py:

> 276 # Iterate over data columns.

> 277 if self.joinedLines:

> 278 points = []

> 279 for xy in row:

> 280 points += [xy[0], xy[1]]

>

> If I use a list comprehension instead, the plot is generated within seconds or

> minutes:

> 278 points = [[xy[0], xy[1]] for xy in row]

> 279

> 280

>

> Also linecharts.py contains the same performance problem but I don't use that.

>

> Best regards

> Sebastian Messing


A Python lister looked at my tests of your code and points out that the list
comprehension is not equivalent to the loop.

The loop produces [a,b,c,d,.....] whereas the comprehension is producing
[[a,b],[c,d],.....], in this case we want the flat list of points because the
Poly functions take [x0,y0,x1,y1,....] type lists of numbers.
--
Robin Becker


More information about the reportlab-users mailing list