[Mono-osx] Horrible performance on Mac, need advice.

LKeene lionel.keene at gmail.com
Mon Jul 20 16:51:24 EDT 2009


Hi Geoff, thanks for the reply.


I no longer believe the disk IO mechanism is at fault. I've written a
super-simple little app that replicates my strategy in single/multi-threaded
modes and performance on the Mac is fine. It's looking more and more like it
may be the drawing (I'm using GDI+ everywhere).

What I'm doing (in an effort to gain fast performance) is to instantiate the
Bitmap objects I'll be using at application startup as follows:


// Instantiate Bitmap object and pinned array:
PixelFormat myPixelFormat = PixelFormat.Format32bppArgb;
pixelFormatSize = Image.GetPixelFormatSize(myPixelFormat) / 8;
stride = this.CanvasWidth * pixelFormatSize;
Channel1BitmapBytes = new byte[stride * this.CanvasHeight];
handle = GCHandle.Alloc(Channel1BitmapBytes, GCHandleType.Pinned); // Pin
the array.
IntPtr channel1PTR =
Marshal.UnsafeAddrOfPinnedArrayElement(Channel1BitmapBytes, 0);
Channel1Bitmap  = new Bitmap(this.CanvasWidth, this.CanvasHeight, stride,
myPixelFormat, channel1PTR);

// ...later on (in Paint event handler for example)...
Graphics grafix = Graphics.FromImage(Channel1Bitmap);



"Channel1BitmapBytes" is a declared globally (within the context of "this")
and, because the array is pinned, I can write to it in multi-threaded
fashion. On Windows this works very well and I get realtime graphics
performance. Could the above be the culprit on OSX? Thanks for any feedback!

-L




Geoff Norton-2 wrote:
> 
> I presumse you're doing a lot of Graphics.FromHwnd (handle); all over  
> the place, this is a huge performance problem on the mac.  Try to  
> coalesce your graphics updates intstead of doing a ton of one-offs.
> 
> -g
> 
> On 20-Jul-09, at 4:29 PM, LKeene wrote:
> 
>>
>> Hello again folks.
>>
>> As the title says, I'm getting GAWD-AWFUL performance with my app when
>> running on mono 2.4.2.1 + Mac OS X.  The exact same binary runs in  
>> fluid
>> real-time on Mono + Windows. Mac performance is literally dozens of  
>> times
>> slower. It (meaning my app) cannot be used on Mac like this. I've  
>> gone from
>> real-time to unusably slow.
>>
>> Here's what I'm seeing: I have data files that consist of 32-bit float
>> values stored as plain old raw binary files.  The data is read from  
>> the
>> disk, processed via some mathematical operations, then rendered on  
>> screen.
>> I'm using 2 threads to read the data; the first thread reads a  
>> scanline of
>> data from the disk, copies it to a temp buffer, signals the other  
>> thread and
>> waits for an event from that thread before continuing. The other  
>> thread gets
>> signalled, copies the data from the temp buffer to a local buffer for
>> processing, signals the first thread to read the next scanline from  
>> the disk
>> and, while that is occuring, begins to process the data in its local  
>> buffer.
>> This is very fast on my windows machine on both Mono and Microsoft  
>> runtimes,
>> but on Mac + Mono it must be two orders of magnitude slower...no, I  
>> am not
>> exagerating. You can imagine some of the looks I got from people  
>> standing
>> around
>>
>> Anyway, shall I prepare a small project that illustrates the  
>> algorithm? The
>> performance differences are so huge I have to believe there is  
>> something
>> fundamentally wrong "close to the metal". Hopefully its something  
>> that can
>> be fixed without too much fuss.
>>
>> Anybody else see this kind of performance hit?:-(
>> -- 
>> View this message in context:
>> http://www.nabble.com/Horrible-performance-on-Mac%2C-need-advice.-tp24507897p24507897.html
>> Sent from the Mono - OSX mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> Mono-osx mailing list
>> Mono-osx at lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/mono-osx
> 
> _______________________________________________
> Mono-osx mailing list
> Mono-osx at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-osx
> 
> 

-- 
View this message in context: http://www.nabble.com/Horrible-performance-on-Mac%2C-need-advice.-tp24507897p24577325.html
Sent from the Mono - OSX mailing list archive at Nabble.com.



More information about the Mono-osx mailing list