Performance issues with many objects

Aug 6, 2010 at 10:13 AM


I work with (actually inherited...) a custom Map Component built on top of BruTile and SharpMap.

This component is being used for fleet management purposes and uses a MapControl2 component to draw many images and ovals.

Unfortunately, the performance scales really badly as the number of objects increases (4-5 thousand), resulting to a not-responding application.

I suspect that this has to do with the fact that drawing happens with the OnPaint event and, thus, continually. Especially the performance of DrawOval is really bad.

How could I remedy this situation? Can I somehow escape the OnPaint drawing or use more efficient methods?

Thanks in advance!


Aug 9, 2010 at 8:52 AM

What 'platform' are you working with, WPF, Silverlight, WinForms? 

SharpMap integration is currently undergoing lots of rework in the Mapsui project (and still a lot to be done). Did you use that version? Or is it based on a old version of what you downloaded here?

In general I am working towards a solution where I use rasterization in a background thread and only render the rasters on the UI thread (in the OnPaint). Also in the current setup each layer retrieves its own data. I would like to use a centralized datafetcher for that. 

Did you use the SharpMapProvider? it draws the ovals into a tile in a background thread and only renders the tile on the foreground thread. This should not be an issue for the OnPaint method. But with 5000 features I expect reading the data could be the problem because most SharpMap data providers read everything for each tile.


Aug 9, 2010 at 4:18 PM
Hi, thanks for the reply. I am using the last stable release (0.9) and WinForms. Actually I figured out that the error was caused by a piece of the existing code. Very interesting the idea of rasterization in a background thread. I am not very familiar with the code, but I think that the drawing of ovals was direct drawing on the Map canvas. I have to look further inside it... thanks again.
Aug 10, 2010 at 12:47 PM

In the BrutTile releases there was never any rendering of features in the OnPaint, so I think this was added by someone on your team.

Maybe a solution is to render the points with the SharpMapProvider. This is rendering SharpMap features to tiles in the background. This is currently being reworked as part of Mapsui. You could look at the last version that was included in BruTile:

For dynamic data this won't work though. In that case you have to render in the OnPaint anyway. 5000 features will be too much for any system to draw dynamically. What you could do is stop drawing while the user interacts with the map. So while panning the features will not show.