User forums > Using Code::Blocks
Slow scrolling? [Ubuntu]
eranif:
Hello,
I wanted to add my 10 cents:
I also noticed performance problems on GTK few years ago on Linux while scrolling with the mouse.
After a long debugging sessions, I changed the following in my code:
- Never call SetStatusMessage directly from the editor, instead fire a custom event using 'AddPendingEvent' in the OnScintillaUpdateUI (EVT_SCI_UPDATEUI) event handler
so my code looks like this:
--- Code: ---void Editor::OnScintillaUpdateUI(wxScintillaEvent &e)
{
...
//update line number
wxString message;
message << wxT("Ln ")
<< curLine+1
<< wxT(", Col ")
<< GetColumn(pos)
<< wxT(", Pos ")
<< pos;
// Always update the status bar with event, calling it directly causes performance degredation
DoSetStatusMessage(message, 1);
...
}
void Editor::DoSetStatusMessage(const wxString &msg, int col)
{
// fire custom event
wxCommandEvent e(wxEVT_UPDATE_STATUS_BAR);
e.SetEventObject(this);
e.SetString(msg);
e.SetInt(col);
wxTheApp->GetTopWindow()->GetEventHandler()->AddPendingEvent(e);
}
--- End code ---
- Line number margin: use a hard coded line margin width, calling TextWidth is a real pain under Linux:
--- Code: --- // Line number margin
#ifdef __WXMSW__
int pixelWidth = 4 + 5*TextWidth(wxSCI_STYLE_LINENUMBER, wxT("9"));
#else
int pixelWidth = 4 + 5*8;
#endif
// Show number margin according to settings.
SetMarginWidth(NUMBER_MARGIN_ID, options->GetDisplayLineNumbers() ? pixelWidth : 0);
--- End code ---
- Two phase drawing, buffered drawing settings are different from one OS to another here are the settings I am using:
--- Code: ---#if defined(__WXMAC__)
// turning off these two greatly improves performance
// on Mac
SetTwoPhaseDraw(false);
SetBufferedDraw(false);
#elif defined(__WXGTK__)
SetTwoPhaseDraw(true);
SetBufferedDraw(false);
#else // MSW
SetTwoPhaseDraw(true);
SetBufferedDraw(true);
#endif
--- End code ---
Adding these 3 changes improved performance noticeably on GTK and Mac for me
Eran
dmoore:
Here's an update.
I played around with the stc example (both C++ and python). The test machine is a netbook running ubuntu 12.04. My test of scrolling responsiveness is to hold the down arrow key for about 10 seconds. On Code::Blocks, in safe mode, scrolling lags badly. I release the key and the editor keeps scrolling for another 10 seconds. I tried switching off the handlers to all of the wxSCI_EVT, but that didn't appear to do much. Similarly tried all of eranif's tips, with no obvious improvement. I also tried switching off some (but not all) idle handlers and timers, and all of the styling calls.
When I run the wxWidgets samples (both C++ and Python) there is no lag. Scrolling stops when you release the key. (I wouldn't say that scrolling is super snappy, however.) Could it be something as simple as the key repeat rate in C::B being set too high?
What is left to switch off in C::B that might help isolate the cause?
oBFusCATed:
dmoore: Have you tried to use a profiler? oprofile for example?
dmoore:
--- Quote from: oBFusCATed on July 18, 2012, 05:48:23 pm ---dmoore: Have you tried to use a profiler? oprofile for example?
--- End quote ---
Someone would suggest a rational approach... :-[
Is oprofile any better than perf? I tried running perf, but the output didn't seem all that useful (most likely user error). I couldn't figure out if there was a way to collapse the lower level calls into the calling code::blocks routines. In the run I did there was a lot of time spent in cairo and pango calls, but that's not really surprising when all i was doing was scrolling.
I also tried valgrind, but having some weird ubuntu issue with callgrind_control:
--- Code: ---moi@home:~$ callgrind_control
No active callgrind runs detected.
--- End code ---
I guess the biggest difference between C::B and the STC sample is the sheer size of C::B. Would it make sense that a single STC event will propagate through many more handlers in C::B than in a stripped down sample?
oBFusCATed:
dmoore: Is this perf: https://perf.wiki.kernel.org/index.php/Main_Page ?
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version