Fix UI lag: revert markdown lexer to 0208d7a (Issue #1314) - #1329
Conversation
rnpnr
left a comment
There was a problem hiding this comment.
There are certainly other things we could be doing so that this is not necessary. I will discuss the code line change with upstream though.
Interestingly when testing I couldn't recreate the issue because my installed vis uses a statically linked LPEG. It seems that embedding LPEG directly in vis provides a much more significant performance boost than I would normally expect. It may be worth making that the default when lua is enabled.
| lex:add_rule('blockquote', | ||
| lex:tag(lexer.STRING, lpeg.Cmt(lexer.starts_line('>', true), function(input, index) | ||
| local _, e = input:find('\n[ \t]*\r?\n', index) -- the next blank line (possibly with indentation) | ||
| return (e or #input) + 1 | ||
| end))) |
There was a problem hiding this comment.
This can only perform worse. It does more than the existing line.
There was a problem hiding this comment.
Disagree, see benchmark in #1314. Reverting decreases runtime by 96%.
There was a problem hiding this comment.
You didn't run the benchmark with only this change. The difference from this hunk alone is insignificant.
There was a problem hiding this comment.
You're right. Working from a functional state like 0208d7a and then benchmarking and improving from there would be a productive path.
|
|
||
| local FOLD_HEADER, FOLD_BASE = lexer.FOLD_HEADER, lexer.FOLD_BASE | ||
| -- Fold '#' headers. | ||
| function lex:fold(text, start_line, start_level) |
There was a problem hiding this comment.
We don't support folding so there is no reason to diverge from upstream here.
There was a problem hiding this comment.
Agree, love to cut out what's not required.
| '\n' * hspace^0 * '```' * hspace^0 * ('\n' + P(-1))) + | ||
| lexer.range(lexer.starts_line('~~~', true), '\n' * hspace^0 * '~~~' * hspace^0 * ('\n' + P(-1))) | ||
|
|
||
| local code_line = lexer.starts_line((B(' ') + B('\t')) * lexer.to_eol(), true) |
There was a problem hiding this comment.
This seems to be the only relevant change.
There was a problem hiding this comment.
Im not sure what this means, would you please clarify? Do you mean only the removal of 68-70 and the addion of 32?
When I diff the files, I see a significant addition added in 16e31ce lines 32-70.
There was a problem hiding this comment.
Sorry, I didn't mean to be unclear. What I meant was that changing code_line rule back to its old form was the only part that was meaningfully changing performance. That is why I pointed out to upstream that it shouldn't have been running on every line and it was fixed. But as shown by your benchmark that was not the only issue.
Title
Fix UI lag in markdown lexer by reverting to 0208d7a (Fixes #1314)
Description
Upon investigation, it was determined that changes made to the markdown lexer
/lua/lexers/markdown.luaafter commit 0208d7a introduced nested loops during the highlighting process. This increased lexing complexity, causing the UI thread to hang or stutter when scrolling through or editing markdown files.Proposed Change
lua/lexers/markdown.luato 0208d7a