Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MadEdit not responding when open .java file #267

Closed
ooab opened this issue May 7, 2018 · 11 comments
Closed

MadEdit not responding when open .java file #267

ooab opened this issue May 7, 2018 · 11 comments
Assignees
Labels
Milestone

Comments

@ooab
Copy link

ooab commented May 7, 2018

Please provide the following information

Madedit-Mod version (or branch): 0.4.12

platform/architecture: windows7

compiler and compiler version:

please describe what symptom you see, what you would expect to see instead and how to reproduce it.

Open a java source file(from main menu, drag&drop or explorer context menu),
madedit ui hangs and not responsing
after about 15 seconds, app recovers.

@LiMinggang LiMinggang self-assigned this May 7, 2018
@LiMinggang LiMinggang added the bug label May 7, 2018
@LiMinggang
Copy link
Owner

LiMinggang commented May 7, 2018

Yes. It has a bug but is hard to reproduce and fix. I made a patch in 0.4.12 that's why it can recover.
18.Fix: Patch for dead/infinite loop in syntax highlighting

The tricky stuff is that the issue would be gone when you load the same file for a second time.

It's a bug of syntax highlighting module.
4e8d92b

I'm not sure when I can fix the issue instead of the patch. If you could reproduce it constantly, it will be helpful.

LiMinggang added a commit that referenced this issue May 11, 2018
LiMinggang added a commit that referenced this issue May 11, 2018
@LiMinggang
Copy link
Owner

Looks the patch worked. Did you want a try?

@LiMinggang
Copy link
Owner

Close it with 0.4.13

@ooab
Copy link
Author

ooab commented Jul 9, 2018

the patch is not valid, the bug can be reproduced with version 0.4.13

@LiMinggang
Copy link
Owner

Is it possible to share the java file you used to reproduce the issue? I used to met the issue by opening HTML file and don not see it for a long time.

@ooab
Copy link
Author

ooab commented Jul 10, 2018

any .java file can reproduce it.

package demos.str;
public class Hello {
    public static void main( String[] args ) {
        // TODO Auto-generated method stub
    }
}

After debugging, i think the problem should be syntax loading:

void MadSyntax::ParseSyntax( const wxString &filename )
{
     
    if( entry == wxT( "keyword" ) )
    {
        wxStringTokenizer tkz( value );
        wxString kw = tkz.GetNextToken();
        wxLongLong t1 = wxGetLocalTimeMillis();
        while( !kw.IsEmpty() )
        {
            if( ( kwlen = kw.size() ) > nw_MaxKeywordLen )
            {
                nw_MaxKeywordLen = kwlen;
            }

            if( !ck->m_CaseSensitive )
                kw.MakeLower();

            ck->m_Keywords.insert( kw );
            m_SyntaxKeywordDict->AddWord(kw);  /* inefficient */
            kw = tkz.GetNextToken();
        }
        wxLongLong t2 = wxGetLocalTimeMillis();
	wxString ms = wxString::Format(wxT("WHILE %dms\r\n"), (t2 - t1).ToLong()); 
        ::OutputDebugString(ms.t_str());
    }
    
}

void PersonalDictionary::AddWord(const wxString& strWord)
{
    wxString word = strWord.Lower();
    if(word.IsEmpty()) return;   
    m_DictionaryWords.Add(strWord.Lower());
    m_DictionaryWords.Sort(); /* inefficient */
}

when loading a syntax file, the code sort the whole dictionary after adding each keyword.
the problem is, in java syntax file, there are thousands of keywords,
the dictionary is sorted again and again, at same time, size of dictionary increased, Sort() getting slower and slower.

more efficient way could be:

void PersonalDictionary::AddWord(const wxString& strWord)
{
    wxString word = strWord.Lower();
    if(word.IsEmpty()) return;   
    m_DictionaryWords.Add(strWord.Lower());
    if( m_AutoSortEnabled ) 
    {
        m_DictionaryWords.Sort(); 
    }
}

m_SyntaxKeywordDict->DisableAutoSort();
while( .. ) 
{
    m_SyntaxKeywordDict->AddWord(kw)
}
m_SyntaxKeywordDict->EnableAutoSort();
m_SyntaxKeywordDict->Sort();

@LiMinggang
Copy link
Owner

Good catch! Will refactor the code for syntax highlighting.

@LiMinggang
Copy link
Owner

I used the code you suggested. Do you want my build or waiting for next release? I'm waiting for wxWigets 3.1.2 to release 0.4.14 which is mainly to fix the High DPI text blurry issue of Windows 10.

@ooab
Copy link
Author

ooab commented Jul 10, 2018

I will wait for your new release.
Currently, spellcheck is useless for me, so I just remove the line 'm_SyntaxKeywordDict->AddWord(kw)' and my build works fine for me.

@LiMinggang
Copy link
Owner

Verified the issue and verified the fix. There was misunderstanding in the communication. I thought the issue you reported is the one I fixed but it is not.

Thanks for reporting the issue and the patch.

@LiMinggang LiMinggang added this to the 0.4.14 milestone Jul 10, 2018
@LiMinggang
Copy link
Owner

Syntax highlight for Java is still a little bit slower than others because of too many keywords. Will try to optimize it to reduce the time you opened two more java files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants