Optimizing displaypipeline performance

Hi, i’am cutomizing ghpython components preview geometry overriding DrawViewportWires() methods. As used @piac in this example

I’am previewing lines, points, meshes and texts using displayPipeline methods available.

I found that when drawing massive quantity of elements, methods like DrawLines() or DrawPoints() are particularly efficient, but with other methods i.e. DrawText() since it takes one element on each call, I need to iterate thousands of time inside DrawVieportWires() what results in a poor navigation performance.

   def DrawViewportWires(self,args):
        MAX_MESH = 500
        MAX_TEXT = 500
        POINT_SIZE = 5
        TEXT_COLOR = System.Drawing.Color.Black
        POINT_STYLE = Rhino.Display.PointStyle.RoundSimple
        #try:
        i = 0
        for value in sorted(self.byValueDict.keys()):
            color = self.colors[i]
            args.Display.DrawPoints(self.byValueDict[value]['points'],POINT_STYLE,POINT_SIZE,color)
            t=0
            if self.showValue:
                for pos in self.byValueDict[value]['textPos']: # this iteration slows performance 
                                                               # even with values as low as t=500
                    if t<MAX_TEXT:
                        args.Display.Draw2dText(str(value),self.colors[i],pos,True,12,"Arial")
                        t += 1
            q = 0
            if self.showMesh:
                for mesh in self.byValueDict[value]['mesh']:
                   if q<MAX_MESH:
                        args.Display.DrawMeshShaded(mesh,Rhino.Display.DisplayMaterial(color))
                        q += 1
            i +=1

I have tried to take off from DrawViewportWires() as much operations as possible, but I cant figure out how to optimize this further: the iteration that still remains inside seems to be unavoidable.

Am I making a bad use of DrawViewportWires()? How does grasshopper components achieve much better results when previewing geometry? Can I expect to have such a good performance (somehow) using python?

thanks

Please try SR9 RC1 that was just released. We made some text drawing optimizations that may help in your case.

thanks steve, I’ll check it on Monday in my script.

Hi @stevebaer , I’am not noticing sensible differences on performance. Nonetheless, I got realize that I’am displaying excesive information on screen (5000 Draw2DText call per frame), wich makes not sense, it’s too much info. I have implemented an clipping box to reduce displayed info focalizing the area to analyze, so now I have a reasonable refreshrate but still displaying enough info to be useful.

By the other hand, I was drawing meshes from DrawViewportWires(), and the performance was not so good as the rest of grasshopper components that preview meshes. then I got realized that there is this DrawViewportMeshes() which previews mesh geometry apparently as fast as expected. (well, not as good, but its ok…)

Thanks
aitor