improve SymbolAtlas.getSymbolCoords performance (#1184)

* remote legacy work-around for old numpy errors

* forgot to remove the numpy_fix import

* require numyp >= 1.8.0

* improve performance of updateData PlotCurveItem (saves about 2us per call)

* improve ScatterPlotItem performance
This commit is contained in:
Daniel Hrisca 2020-05-04 23:42:03 +03:00 committed by GitHub
parent a76d9daec2
commit f7364f52b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -122,26 +122,35 @@ class SymbolAtlas(object):
""" """
Given a list of spot records, return an object representing the coordinates of that symbol within the atlas Given a list of spot records, return an object representing the coordinates of that symbol within the atlas
""" """
sourceRect = np.empty(len(opts), dtype=object)
sourceRect = []
keyi = None keyi = None
sourceRecti = None sourceRecti = None
for i, rec in enumerate(opts): symbol_map = self.symbolMap
key = (id(rec[3]), rec[2], id(rec[4]), id(rec[5])) # TODO: use string indexes?
for i, rec in enumerate(opts.tolist()):
size, symbol, pen, brush = rec[2: 6]
key = id(symbol), size, id(pen), id(brush)
if key == keyi: if key == keyi:
sourceRect[i] = sourceRecti sourceRect.append(sourceRecti)
else: else:
try: try:
sourceRect[i] = self.symbolMap[key] sourceRect.append(symbol_map[key])
except KeyError: except KeyError:
newRectSrc = QtCore.QRectF() newRectSrc = QtCore.QRectF()
newRectSrc.pen = rec['pen'] newRectSrc.pen = pen
newRectSrc.brush = rec['brush'] newRectSrc.brush = brush
newRectSrc.symbol = rec[3] newRectSrc.symbol = symbol
self.symbolMap[key] = newRectSrc
symbol_map[key] = newRectSrc
self.atlasValid = False self.atlasValid = False
sourceRect[i] = newRectSrc sourceRect.append(newRectSrc)
keyi = key keyi = key
sourceRecti = newRectSrc sourceRecti = newRectSrc
sourceRect = np.array(sourceRect, dtype=object)
return sourceRect return sourceRect
def buildAtlas(self): def buildAtlas(self):