1

I'm working on a project were I need to draw N ellipses every X milliseconds, where 0 <= N <= 10^5 and 5 <= X <= 500.

I started using WPF, and its relative controls like Canvas for the viewport and Ellipse controls for the ellipses. I store the ellipses in a list and:

  • Every time the number of ellipses increases I add a new ellipse to my list.
  • Every time the number of ellipses stored in myViewport.Children is less than myListOfEllipses.Count I add these ellipses to my viewport, otherwise I remove the ellipses in excess from the viewport without remove them from my list.
  • For each ellipse I compute the new position and I use the Canvas.SetLeft and Canvas.SetTop methods.

The performance is quite good, but there is a slowdown when X is set to the minimum and N is greater than 1000.

I thought about using DrawingVisuals, but I suppose that drawing and displaying a bitmat is also faster. So, I decide to replace my viewport with an Image control that has as Source a WriteableBitmap and to use WriteableBitmapEx library.

  • Every time I clear the viewport using myBitmap.Clear(Colors.White).
  • Every time I draw new ellipses using myBitmap.FillEllipse(...).

Well, the problem is the latter way is much slower than the former. How is it possible? Where am I wrong? How can I improve the performance of my bitmap?

Nick
  • 10,309
  • 21
  • 97
  • 201
  • I'm guessing you might just be hitting a wall in terms of software-based rendering. You may have to consider diving into GPU programming instead (there are a few wrapper libraries out there that may make your life easier, e.g., [SlimDX](http://slimdx.org/)) First I would recommend you benchmark your own code _without_ rendering to the screen. Make a POCO Ellipse object and do all the math you normally do to set its position/size/colour. If that isn't running fast enough then no renderer in the world will (at the very least it will tell you how fast the renderer needs to run) – Chris Sinclair May 04 '14 at 12:08
  • When N is getting high, chances of overlap raises. Maybe by testing the inner bounding box of one ellipse against inner bbox of other ellipses you could save quite few draws. Other path i see i to redraw only if required / only the part of screen, but there are to few data here to be more precise. Q : Do the ellipses have a 'z'? – GameAlchemist May 04 '14 at 17:01
  • @GameAlchemist no, ellipses don't have Z-order, and I already draw only the ellipses that can be seen. – Nick May 05 '14 at 10:43

0 Answers0