All Swing text components continuously repaint while they have focus due to the Caret blinking. This is something that cannot be avoided.
As for re-lexing, this is actually related to the repainting. RSTA doesn't store any token information about the parsed document (well, it stores the token type of the last token on each line, but no lexical/color information about the document as a whole), and so every time it repaints, it has to do some re-parsing. This isn't as bad as it sounds for a few reasons:
- As the caret blinks, it only re-parses the line the caret is currently on, not the entire document. Again, this is due to needing to repaint around the caret.
- As you scroll, it parses each line as it becomes visible, but not again once it's visible on-screen. This is thanks to Swing's double-buffering.
- RSTA's parsing is super-fast. It involves no memory allocation. It's literally a scan through the chars on a line. More cycles are probably spent in most common usage scenarios, such as the viewToModel() call to place the Caret when clicking on a random location in the editor.
It all comes down to RSTA's trade-off of using less memory to support larger documents. The tradoff of re-parsing seemed justified since the parsing is so cheap. If you're seeing RSTA use any measurable CPU while sitting idle (i.e. > 0% in Task Manager), let me know and perhaps we can look into it.