[Gtk-sharp-list] gtk-dotnet performance

Scott Ellington scottellington at comcast.net
Wed Mar 1 12:27:41 EST 2006


On Wed, 2006-03-01 at 13:02 -0500, Jonathan Resnick wrote:
> Hi Scott,
> 
> Thanks so much for taking a look at my sample.  I think the memory leak is
> not so much a leak as just the latency of the garbage collector not being
> able to recover the memory as fast as it is used up.

This should not be the case.  As long as you are calling dispose on the
correct objects, that memory should be regained instantaneously.  In the
app I linked, I am constantly creating and destroying bitmaps without
any memory issues.

> 
> For that reason, it would really be best if I didn't have to create the
> Graphics object inside of the loop, which is why I started looking at using
> an intermediate Pixmap.  I'm surpised you're not seeing the 1 second times
> that I observed when drawing to the Pixmap.  Not to be pedantic, but I
> forgot to mention in my original post that you need to change the value
> passed to the PictureArea() constructor, inside of the MainWindow()
> constructor, to false in order for it to use the pixmap option.  If you have
> a chance to try this and see if you observe the 1 second times, that would
> be great.  I hope I'm not asking too much here... I just can't understand
> why it should be any slower to copy an image to a Pixmap than directly to a
> DrawingArea.

Well your app defaulted to draw to the pixmap.  I had to switch the bool
to true to see the memory leak.

> 
> On the other hand, if you know of any other way to display a
> System.Drawing.Bitmap inside a Gtk window that might work better, I'm open
> to suggestions.

Check out the code I linked.

Scott

> 
> Thanks again,
> Jonathan
> 
>  
> 
> -----Original Message-----
> From: Scott Ellington [mailto:scottellington at comcast.net] 
> Sent: Wednesday, March 01, 2006 11:26 AM
> To: Jonathan Resnick
> Cc: gtk-sharp-list at lists.ximian.com
> Subject: Re: [Gtk-sharp-list] gtk-dotnet performance
> 
> Hi Jonathan,
> 
> I have just tried your test app and I am not seeing times near 1 second:
> 
> Frame 197: 116 msec
> Frame 198: 148 msec
> Frame 199: 106 msec
> 
> As for your first option, there is definitely a memory leak ocurring.  I
> could not pinpoint where that is, but I believe you are incorrect in
> thinking that it is the Gtk.DotNet.Graphics.FromDrawable (window) in the
> Expose Event.  I do that exact thing with no such memory leak:
> 
> http://forge.novell.com/modules/xfmod/svn/svnbrowse.php?uri=filedetails.php%
> 3Frepname%3Dappomattox%26path%3D%252Ftrunk%252FAppomattox%252Fsrc%252FAppoma
> ttox.Gui.Components%252FMapCanvas.cs
> 
> Scott
> 
> On Tue, 2006-02-28 at 22:07 -0500, Jonathan Resnick wrote:
> > I am trying to port an open-source medical imaging application from 
> > .NET to Mono so that it can run on Linux. A large part of the codebase 
> > is based on the System.Drawing library - therefore I am trying to use 
> > the gtk-dotnet bridge so that GTK can be used as a front end. However, 
> > I'm having a hard time getting decent performance, and as far as I can 
> > tell, the problems seem to stem from the gtk-dotnet component.
> > 
> > I've attached a sample application that just tries to flip two 
> > System.Drawing.Bitmaps to a Gtk.DrawingArea, alternating them, in a 
> > tight loop. It measures the time taken for each flip and prints it to the
> console.
> > 
> > On Linux, I observe the following behaviour:
> > 
> > 1. My first approach was to try drawing directly to the screen 
> > (_drawDirect = true in the OnExposeEvent handler). The performance is 
> > good for roughly the first 100 or so loop iterations, but then it 
> > quickly degrades. It seems as though the system starts to run out of 
> > memory, which seems to be caused by creating a Graphics object using 
> > Gtk.DotNet.Graphics.FromDrawable inside the OnExposeEvent handler.
> > 
> > 2. My second approach was to try drawing to an intermediate Pixmap 
> > (_drawDirect = false in the OnExposeEvent handler), so as to avoid 
> > having to create a Graphics object each time. In this case, the 
> > performance is constant over the entire duration of the loop. However, 
> > the performance is pretty bad, taking roughly 1 second per flip, which 
> > is not acceptable for our purposes (and I'm running it on a reasonably
> powerful laptop machine).
> > 
> > If someone with a solid understanding of Gtk/Gdk could look at my 
> > sample code and point out to me where I'm going wrong, it would be a 
> > huge help in getting this application running on Linux.
> > 
> > Thanks,
> > 
> > Jonathan
> > 
> > _______________________________________________
> > Gtk-sharp-list maillist  -  Gtk-sharp-list at lists.ximian.com 
> > http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
> 



More information about the Gtk-sharp-list mailing list