Skip to content

Capturing and applying a pattern causes performance loss #167

@RedCMD

Description

@RedCMD

Create a syntax highlighter with the following code:
image

{
	"scopeName": "source.redcmd.syntax.lag",
	"patterns": [
		{
			"match": "a",
			"name": "keyword.control",
			"captures": {
				"0": { "patterns": [] }
			}
		}
	]
}

Create a test file, apply that syntax highlighter and type a few thousand a's
notice the increasing lag and vscode eventually giving up trying to match and just highlighting the rest of the file with the last token
image
(you may need to increase editor.maxTokenizationLineLength to 10,000 or so to see results)

Now remove "patterns": []
notice all lag disappearing and everything tokenizes correctly
image

Also notice that "patterns": [] can be empty (which would be a different bug in itself) and still causes lag
The capture group itself does need to capture something (does not happen with a empty group)
and the size of the capture text inside the group does not matter

Without "patterns": []; my machine is able to highlight almost 680,000 a's
While with patterns; it can barely highlight 6,500
Thats almost exactly 100x times faster

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions