Author Topic: Time to refresh the CC Toolbar  (Read 11739 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5358
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Time to refresh the CC Toolbar
« on: December 21, 2012, 07:04:28 am »
I just enable the debug log in codecompletion.cpp

Code
#define CC_CODECOMPLETION_DEBUG_OUTPUT 1

I see that the CC toolbar get refreshed many times if I click in the same function body.
E.g.
Code
wxString func()
{
  wxString  rv;

  rv += wxT('a');    //*** first step: click here
  rv += wxT('b');
  rv += wxT('c');    //*** second step: click here

  return rv;
}

Here, the click is all in the same function body, but I see that the function:
Code
void CodeCompletion::ParseFunctionsAndFillToolbar()

called multiply times.

Is that necessary?  We don't need to refresh the toolbar if we click in the same function body.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5358
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Time to refresh the CC Toolbar
« Reply #1 on: December 21, 2012, 07:10:45 am »
Code
void CodeCompletion::EditorEventHook(cbEditor* editor, wxScintillaEvent& event)
{
.....
.....

    if (control->GetCurrentLine() != m_CurrentLine)
    {
        if (m_NeedReparse)
        {
            TRACE(_T("EditorEventHook: Starting m_TimerRealtimeParsing."));
            m_TimerRealtimeParsing.Start(REALTIME_PARSING_DELAY, wxTIMER_ONE_SHOT);
            m_CurrentLength = control->GetLength();
            m_NeedReparse = false;
        }

        if (event.GetEventType() == wxEVT_SCI_UPDATEUI)
        {
            m_ToolbarNeedRefresh = true;
            TRACE(_T("EditorEventHook: Starting m_TimerToolbar."));
            if (m_TimerEditorActivated.IsRunning())
                m_TimerToolbar.Start(EDITOR_ACTIVATED_DELAY + 1, wxTIMER_ONE_SHOT);
            else
                m_TimerToolbar.Start(TOOLBAR_REFRESH_DELAY, wxTIMER_ONE_SHOT);
        }
    }

    // allow others to handle this event
    event.Skip();
}

Look, this value is force to be true
Code
m_ToolbarNeedRefresh = true;
, even we have later set it to false.
Code
void CodeCompletion::ParseFunctionsAndFillToolbar()
{

.....
.....
    // Does the toolbar need a refresh?
    if (m_ToolbarNeedRefresh || m_LastFile != filename)
    {
        // Update the last editor and changed flag...
        if (m_ToolbarNeedRefresh)
            m_ToolbarNeedRefresh = false;
        if (m_LastFile != filename)
        {
            TRACE(_T("ParseFunctionsAndFillToolbar() : Update last file is %s"), filename.wx_str());
            m_LastFile = filename;
        }

        // ...and refresh the toolbars.
        m_Function->Clear();

        if (m_Scope)
        {
            m_Scope->Freeze();
            m_Scope->Clear();

            // add to the choice controls
            for (unsigned int idxSc = 0; idxSc < m_ScopeMarks.size(); ++idxSc)
            {
                int idxFn = m_ScopeMarks[idxSc];
                const FunctionScope& fs = m_FunctionsScope[idxFn];
                m_Scope->Append(fs.Scope);
            }

            m_Scope->Thaw();
        }
        else
        {
            m_Function->Freeze();

            for (unsigned int idxFn = 0; idxFn < m_FunctionsScope.size(); ++idxFn)
            {
                const FunctionScope& fs = m_FunctionsScope[idxFn];
                m_Function->Append(fs.Scope + fs.Name);
            }

            m_Function->Thaw();
        }
    }

    // Find the current function and update
    FindFunctionAndUpdate(ed->GetControl()->GetCurrentLine());

    // Control the toolbar state
    EnableToolbarTools(fileParseFinished);
}


Look:
Code
        if (m_ToolbarNeedRefresh)
            m_ToolbarNeedRefresh = false;
Here
Code
m_ToolbarNeedRefresh = false;
in this function, but as I can see, this member variable is always be set in the editor hook handler (CodeCompletion::EditorEventHook).
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9614
Re: Time to refresh the CC Toolbar
« Reply #2 on: December 21, 2012, 08:46:13 am »
...I think the problem here was the case, that the file was modified from externally. Then, you don't know where you are, the content could have been change completely. Thus, the toolbar better does a refresh.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5358
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Time to refresh the CC Toolbar
« Reply #3 on: December 21, 2012, 09:06:56 am »
...I think the problem here was the case, that the file was modified from externally. Then, you don't know where you are, the content could have been change completely. Thus, the toolbar better does a refresh.
I don't think this is related to my original question.

Currently, I think if I can detect the click (caret position) remains in the same function body, we don't need to update the toolbar. If you see your screen carefully, you will see it refresh everytime when you click the caret(event in the same function body).
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13393
    • Travis build status
Re: Time to refresh the CC Toolbar
« Reply #4 on: February 04, 2013, 11:55:34 am »
I've just had slowness, probably caused by the toolbar in one of the larger files of C::B, probably codecompletion.cpp.
No external files has have been modified, but every move of the cursor caused a slowdown and a flicker of the toolbar.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5358
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Time to refresh the CC Toolbar
« Reply #5 on: February 04, 2013, 02:49:46 pm »
I've just had slowness, probably caused by the toolbar in one of the larger files of C::B, probably codecompletion.cpp.
No external files has have been modified, but every move of the cursor caused a slowdown and a flicker of the toolbar.
OK, you confirm the bug, thanks.
As I said before, the reason is: the toolbar's contents(wxChoice's contents) were always calculated and refreshed in the editor hook function, after
Code
if (event.GetEventType() == wxEVT_SCI_UPDATEUI)
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Time to refresh the CC Toolbar
« Reply #6 on: February 04, 2013, 04:09:53 pm »
Look at the refresh logic in the most recent patch in my queue; some of it probably would be applicable here as well.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5358
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Time to refresh the CC Toolbar
« Reply #7 on: February 04, 2013, 04:29:28 pm »
Look at the refresh logic in the most recent patch in my queue; some of it probably would be applicable here as well.
CCsemant4.patch? (see attachment if other forum user want to test)

CC's toolbar have mainly two functions:
1, if the user select a function (wxChoice), then the caret will jump to the selected function in the editor.
2, if the user move the caret in the editor, the toolbar(wxChoice) should be updated to indicate which function was the caret located in.

I think the above "2" currently cause the lag, and should be optimized, I mean, if the user move the caret in the same function scope. (a function body usually contains a starting brace line and the closing brace line), we don't need to update the wxChoice.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.