How to speed up the PSI parsing of files?



     I am now customizing a language by writing a BNF file and using the Grammar-kit plug-in to automatically generate a Java file. However, when the number of lines of code in the text is large (for example, 10,000 lines), the psi parsing is time-consuming after each text modification. As a result, code compeletion is very slow, and frame freezing occurs when editing new lines.
           After searching for documents, we find that the intellij platform supports incremental parsing. Therefore, some element types are inherited from IReparseableElementType to implement incremental parsing. However, incremental parsing cannot be implemented in many scenarios.
          What other methods can be used to improve the psi parsing speed?



Comment actions Permalink

For example:

The code structure is as follows:

import ab from'mn';

class person {
       private name:string ="c";

after the "import ab from'mn';" statement is modified, the psi parsing of the entire file is triggered and the " public ASTNode parse(IElementType t, PsiBuilder b) "  method is executed. Is there a method to perform incremental parsing? such as  only parse import statements.

Comment actions Permalink

Another question: When you press the newline key, the newline freezes. Is there a good solution to this problem?

Comment actions Permalink

It is hard to give generic advice without seeing the actual Grammar and Lexer definitions with some performance measurements.


Please sign in to leave a comment.