wxDC DrawLines on MacOS Performance Problem

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
timrprobocom
In need of some credit
In need of some credit
Posts: 3
Joined: Tue Sep 13, 2016 5:43 am

wxDC DrawLines on MacOS Performance Problem

Post by timrprobocom » Fri Dec 13, 2019 7:10 pm

I have a wxWidgets telemetry application that needs to draw 6,000 short lines several times per second. It's been in production use for several years (although production is on Linux, not Mac). I'm sure I've tried the line-drawing page on MacOS before, but if so, it's been a while. On WIndows, drawing those lines takes less than 100ms. On Linux, it takes less than 100ms. On MacOS, it takes many, many seconds.

I've isolated this into a simple test case that still shows the problem: http://github.com/timrprobocom/drawline-macos.git. The readme describes the performance differences. In order to test this on my Mac in the office, I had to reduce the number of lines from 6,000 to 600, and even that takes 5 BILLION CPU cycles, or about 2.5 seconds.

Something is very wrong with that. I'm using 3.1.3 on Windows, 3.0.4 on the other platforms. I looked over the source code, but I didn't see anything immediately obvious. Suggestions are welcome.

User avatar
doublemax
Moderator
Moderator
Posts: 14525
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDC DrawLines on MacOS Performance Problem

Post by doublemax » Fri Dec 13, 2019 7:59 pm

I don't work under OSX, so i can't test this. But looking at your code, the use of wxClientDC looks suspicious. Does your real code do the same? If yes, please convert your code to draw in a paint event handler onto a wxPaintDC and check if it makes any difference.
Use the source, Luke!

timrprobocom
In need of some credit
In need of some credit
Posts: 3
Joined: Tue Sep 13, 2016 5:43 am

Re: wxDC DrawLines on MacOS Performance Problem

Post by timrprobocom » Fri Dec 13, 2019 8:07 pm

It's not suspicious in any way. If you're drawing in a paint handler, you use a wxPaintDC. If you're drawing outside of a paint handler, you use a wxClientDC. All of that is just for convenience, anyway. The low-level drawing is all done in the base wxDC class.

Because I'm drawing in a timer event, we're guaranteed that I'm in the UI thread here.

As it turns out, in the production code, the drawing is done in a function that accepts a wxDC. It gets called from the paint handler with a wxPaintDC, and from a timer handler with a wxClientDC. Same results.

User avatar
doublemax
Moderator
Moderator
Posts: 14525
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDC DrawLines on MacOS Performance Problem

Post by doublemax » Fri Dec 13, 2019 10:12 pm

No idea then. Please try asking on the wx-users mailing list where the actual wx developers can see it:
https://groups.google.com/forum/#!forum/wx-users

They will most likely ask you to try with wx 3.1.3, so you should do that first.
Use the source, Luke!

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3816
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxDC DrawLines on MacOS Performance Problem

Post by ONEEYEMAN » Fri Dec 13, 2019 10:42 pm

Hi,
first the usual stanza:
1. Version of wx?
2. Version of OSX you do testing on?
3. Minimal OSX version set during configure?

Now more serious one:
4. IIRC, drawing on wxClientDC on OSX is shaky. Stefan recommends (read - strongly suggest) do the drawing inside the paint event using wxPaintDC.

At the very least - try it and see if it makes any difference.

Thank you.

Post Reply