Textmate grammar freezes with long string constant
Opened this issue · 4 comments
From @swbrenneis in microsoft/vscode#79640
Paste the following into a java file:
package org.mytest;
class MyTest {
void doMyTest() {
testString = "A900102008Exx xxxxxxxxxxxxxxxxxxxxxx T1201801210000P0000000002421000002Exxxxxx P021000021JPxxxxxxxxxxxxxxxxx 021000021xxxxxxxxxxxxxxxxxxx 0000000222100D P021000089xxxxxxxxxxxx 021000089xxxxxxxxxxxx 0000000012100C P051000017xxxxxxxxxxxxxxx 051000017xxxxxxxxxxxxxxx 0000000020000C P081000032xxxxxxxxxxxxxxx 081000032xxxxxxxxxxxxxxx 0000000020000D P121000248xxxxxxxxxxxxxxxx 121000248xxxxxxxxxxxxxxxx 0000000210000C ";
}
}
The grammar will cause a freeze
Thanks for reporting, I will have a look.
I root caused the issue - variable pattern causes the problem, will try fixing it.
Seems to be caused by class
:
language-java/grammars/java.cson
Lines 279 to 367 in 047fd33
and
record
:language-java/grammars/java.cson
Lines 1286 to 1348 in 047fd33
Commenting both out reduces lag massively
the [\\w\\s]*
and \\b(?:class|(?<!@)interface|enum)\\s+
clashes quite badly causing catastrophic backtracking when no class/record is found on a standalone word
combine that with the begin
rule is a 0width lookahead with no outside anchoring points
not a good recipe for performance
changing (?=\\w?[\\w\\s-]*\\b(?:class|(?<!@)interface|enum)\\s+[\\w$]+)
to (?=(?>(?!\\b(?>class|(?<!@)interface|enum)\\s)\\w++|[\\w\\s-&&[^cei]]++)*+\\b(?>class|(?<!@)interface|enum)\\s+[\\w$])
helps out alot, but does not remove the lag entirely
and the same for record
: (?=\\w?[\\w\\s]*\\b(?:record)\\s+[\\w$]+)
=> (?=(?>(?!\\brecord\\s)\\w++|[\\w\\s&&[^r]]++)*+\\brecord\\s+[\\w$])