Skip to content

regression: severe nonlinear slowdown in artist creation #370

Closed
@mspacek

Description

@mspacek

I was running 0.99.3 for the longest time, but recently switched to git master. Among other issues, I've noticed a big slowdown in the creation of Line2D objects in my app, which embeds a mpl figure within a PyQt4 window. After a whole lot of bisecting, I found the offending commit: ca9d6b2 by mdboom on 2010-05-28. The immediately preceding commit 7d7590e on the same day doesn't have this issue. It's quite a big diff in the cbook.CallbackRegistry, none of which I understand. I'm guessing the problem applies to any artist, not just Line2Ds, but I haven't tried any other type. Here's a minimal program that demonstrates the slowdown:

import sys
import time
from PyQt4 import QtGui

from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg
from matplotlib.lines import Line2D
from matplotlib.figure import Figure

class MyFigureCanvasQTAgg(FigureCanvasQTAgg):
    def __init__(self):
        figure = Figure()
        FigureCanvasQTAgg.__init__(self, figure)
        self.ax = figure.add_axes([0, 0, 1, 1])
        t0 = time.time()
        self.init_lines()
        print('init_lines() took %.3f sec' % (time.time()-t0))

    def init_lines(self):
        for i in range(3000):
            line = Line2D([], [], visible=False)
            self.ax.add_line(line)

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    window = MyFigureCanvasQTAgg()
    window.show()
    sys.exit(app.exec_())

This creates thousands of empty invisible lines. Here are the results on my machine (Ubuntu Maverick, with stock Qt 4.7.0 and PyQt4 4.7.4), before and after the commit, and for git master:

3000 lines:
before: 0.9 sec
after: 11.9 sec
master: 11.9 sec

6000 lines:
before: 1.8 sec
after: 60 sec
master: 60 sec

So, the problem is a nonlinear function of the number of lines created.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions