wxMac VERY VERY SLOW at runtime

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
joeman
Knows some wx things
Knows some wx things
Posts: 27
Joined: Sun Jul 31, 2005 5:11 pm
Location: France

wxMac VERY VERY SLOW at runtime

Post by joeman » Thu Aug 11, 2005 8:49 am

Hi All
I've developed a soft with wxwidget 2.6.1, it compiles on both mac osx tiger and windows.
Runiing the program on win xp works very well, as opposed to the mac version, wich also works BUT VERY VERY SLOWLY !
For instance, opening a dialog file would requires about 3 sec before seeing the dialog !
All the soft is working very slowly on Mac osx !
Any idea would be greatly appreciated
Thnaks
J

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Thu Aug 11, 2005 8:53 am

Hmm...
I can only give some general tips I'm sure you already know:
1. Compile in release mode
2. Disable profiling
3. Get gcc to optimize for speed (-Os)
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

joeman
Knows some wx things
Knows some wx things
Posts: 27
Joined: Sun Jul 31, 2005 5:11 pm
Location: France

Post by joeman » Thu Aug 11, 2005 9:00 am

hmmm tis is what I tried ...
The execution is a little bit faster, anyway it is still VERY slow, unusable ..
J

Ryan Wilcox
I live to help wx-kind
I live to help wx-kind
Posts: 194
Joined: Mon Aug 30, 2004 1:26 pm
Location: PA, USA
Contact:

Post by Ryan Wilcox » Thu Aug 11, 2005 4:04 pm

Very interesting. There's some profiling tools on OS X, found in /Developer/Applications/Performance Tools. You'll probably want Shark - talk about an incredible amount of information. There's a PDF on Shark at /Developer/ADC Reference Library/documentation/CHUD/SharkUserGuide.pdf, and I'm sure you'll be able to find more information at http://developer.apple.com

(There's also an app called Sampler, at least there is on my machine. I would use Shark first if I were you - Shark makes Sampler look like a kids toy.)

Or you could use Activity Monitor to figure out what application is hogging the CPU. It could be yours, but I've also seen other apps hog (for example, Classic, which isn't really an app, but it can go into a tailspin about things)
Ryan Wilcox
Wilcox Development Solutions
http://www.wilcoxd.com

KevinHock
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 236
Joined: Sat Sep 04, 2004 1:49 pm
Location: Ohio, USA
Contact:

Post by KevinHock » Thu Aug 11, 2005 4:07 pm

BTW, what kind of Mac are you using (CPU, RAM, etc)?

I have found that loading in system libraries can be a bit slow, including things like the first time you play a sound or the first time you open a dir dialog.

If it's not the system, it's not the fault of wxWidgets because otherwise this would be a very common complaint and it isn't. ;)

joeman
Knows some wx things
Knows some wx things
Posts: 27
Joined: Sun Jul 31, 2005 5:11 pm
Location: France

Post by joeman » Thu Aug 11, 2005 5:26 pm

I'm using a Mac mini with 512MB ram, G4 @ 1.25GHz
it should be enough ...
I'll check for this profiling
thnanks
J

KevinHock
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 236
Joined: Sat Sep 04, 2004 1:49 pm
Location: Ohio, USA
Contact:

Post by KevinHock » Fri Aug 12, 2005 5:56 am

Yup, a mini is a decently fast Mac. However still don't be suprised to see slight pauses when system functions are first used.

joeman
Knows some wx things
Knows some wx things
Posts: 27
Joined: Sun Jul 31, 2005 5:11 pm
Location: France

Post by joeman » Fri Aug 12, 2005 6:23 am

I perfomed few tests using the mac monitor, the CPU usage is about 90% even if the program is in a idle state ... !
Any idea ?
thnaks

joeman
Knows some wx things
Knows some wx things
Posts: 27
Joined: Sun Jul 31, 2005 5:11 pm
Location: France

Post by joeman » Fri Aug 12, 2005 9:30 am

Well after profiling the soft, the problem comes from the OnDialogPaint event which is called all the time.
I've a background bmp and the OnDialogPaint function is :

void fw_upgrader_ui::OnDialogPaint( wxPaintEvent& event )
{
wxPaintDC dc( this );
wxBitmap background_bmp = GetBitmapResource(wxT("main_1.png"));
if (background_bmp.Ok())
dc.DrawBitmap(background_bmp, 0, 0, FALSE);
}

When commenting the contents of the above function, my bmp is no more displayed but the program execution is normal, it is not slow as it was

What do I have to do ?
thnaks

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Fri Aug 12, 2005 9:42 am

Hi!
Try painting the image using wxEraseEvent in an EVT_ERASE_BACKGROUND.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

joeman
Knows some wx things
Knows some wx things
Posts: 27
Joined: Sun Jul 31, 2005 5:11 pm
Location: France

Post by joeman » Fri Aug 12, 2005 10:16 am

just tried, I can see the background bmp but it is now over the controls so I cannot see my buttons, checkboxes ...

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Fri Aug 12, 2005 10:22 am

Hmm... This should not happen as you'd paint the image first.
Did you use GetDC() to get the correct dc to draw on?
Maybe post your updated code.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

KevinHock
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 236
Joined: Sat Sep 04, 2004 1:49 pm
Location: Ohio, USA
Contact:

Post by KevinHock » Fri Aug 12, 2005 3:57 pm

I had a similar problem when I was using Refresh and Update, because my logic was faulty and calling these made them get called again, thereby forcing the window to repaint constantly. Any chance that's what's going on here?

ssigala
Earned some good credits
Earned some good credits
Posts: 109
Joined: Fri Sep 03, 2004 9:30 am
Location: Brescia, Italy

Post by ssigala » Fri Aug 12, 2005 4:10 pm

Code: Select all

    wxPaintDC dc( this );
    wxBitmap background_bmp = GetBitmapResource(wxT("main_1.png"));
    if (background_bmp.Ok())
	dc.DrawBitmap(background_bmp, 0, 0, FALSE);
I don't know the reason for the continous wxPaintEvent, but...

GetBitmapResource() loads the bitmap every time from the disk?

If it is so, this may be overkilling: you should create the bitmap once in the window constructor, then delete it in the destructor.
Sandro Sigala - Kynosoft, Brescia

joeman
Knows some wx things
Knows some wx things
Posts: 27
Joined: Sun Jul 31, 2005 5:11 pm
Location: France

Post by joeman » Sat Aug 13, 2005 10:30 pm

GetBitmapResource() loads the bitmap every time from the disk?

right, this was the problem.

I embedded the bitmap as an xpm into a .h which is included in the project. It now works fine, at normal speed !

Thanks to all
J

Post Reply