Developer forums (C::B DEVELOPMENT STRICTLY!) > CodeCompletion redesign
CC: Expensive calls on opening new files
dmoore:
When opening a new file, the following gets called:
--- Code: ---void CodeCompletion::OnEditorActivated(CodeBlocksEvent& event)
{
EditorBase* eb = event.GetEditor();
if (IsAttached() && m_InitDone)
{
m_NativeParsers.OnEditorActivated(eb);
m_FunctionsParsingTimer.Start(1000, wxTIMER_ONE_SHOT); // one second delay should be ok
}
event.Skip();
}
--- End code ---
which eventually results in this call
--- Code: ---bool Parser::ParseBufferForFunctions(const wxString& buffer)
{
ParserThreadOptions opts;
opts.wantPreprocessor = m_Options.wantPreprocessor;
opts.useBuffer = true;
opts.bufferSkipBlocks = true;
opts.handleFunctions = true;
ParserThread* thread = new ParserThread(this,
buffer,
false,
opts,
m_pTempTokens);
return thread->Parse();
}
--- End code ---
on the main thread??
this is really time consuming for big files...
also note this hook gets called hundreds if not thousands of times when opening a file (should shut down the event propagation in the sdk until the text has been inserted?):
--- Code: ---void CodeCompletion::EditorEventHook(cbEditor* editor, wxScintillaEvent& event)
{
ConfigManager* cfg = Manager::Get()->GetConfigManager(_T("code_completion")); //EXPENSIVE??
if (!IsAttached() ||
!m_InitDone)// ||
!cfg->ReadBool(_T("/use_code_completion"), true)) //cfg-Read... EXPENSIVE??
{
event.Skip();
return;
}
...
--- End code ---
dmoore:
I patched cbeditor to restrict editorhook calls during file opens. CC reports only ~ 200 events with patch (vs ~700,000 unpatched) when loading a 9mb file. patch: http://developer.berlios.de/patch/index.php?func=detailpatch&patch_id=2072&group_id=5358
this roughly halves the time until you see the editor spring up (at which time function parsing begins on the main thread - i haven't attempted to fix this...)
dmoore:
PS: please move if this doesn't belong here (the thread stuff is more relevant to this sub-forum, perhaps)
rickg22:
dmoore: Please share more! I need to know everything.
OK, first of all: The "m_FunctionsParsingTimer.Start(1000, wxTIMER_ONE_SHOT);" was added so Code Completion would wait at least some time before starting to parse. If a file was added to the project, the timer would be reset and the countdown would start from -1000 ms again. When all files had finished opening, the timer would advance to 0 and parsing would begin. So yes, basically it was a way to delay the parsing until the project had been finished.
However, I didn't know anything about the hooks. What tests exactly did you do to realize this was called thousands of times?
Update: I added a debug log to cbEditor::OnScintillaEvent(wxScintillaEvent& event). It displays a message along with a cumulative number. The number i got was 17242 effective calls during project opening. You're right.
But I got a better solution than your patch. It's called ProjectManager::IsBusy(). Returns true when the project is loading/closing.
rickg22:
What do you know, it works! :) It only gets 17 effective calls during project opening.
I'll do something similar to code compleition's OnEditorActivated. Hats off for your discovery. :)
Update: Guess what, biplab had already fixed that part. I'm just cleaning it up.
Navigation
[0] Message Index
[#] Next page
Go to full version