-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bracket pair parsing runs twice on keypress #163304
Comments
On which document did you try this out? The entire thing is 5.98ms, so it is 2% for me. Also, it is by design that it reacts on both content changes and token changes - maybe it can be optimized, but I wouldn't call this a "bug".
Here is a description of the algorithm: This section is about how incrementality is achieved: Maybe there are some cheap optimizations that I missed though (e.g. getting rid of recursion). |
I was mostly using InputHandler.ts from xterm.js or terminalInstance.ts from vscode yesterday.
This is on your fast machine that is likely quite a ways off the average user (and the 50% below the average). I think for that screenshot I was using 4x CPU throttling on my main computer (Windows 11) to emphasise slow parts.
Maybe I'm misunderstanding the incremental parsing, but if it's could do in less time what it does in content change after tokenization, it should be changed. To clarify, this is how I propose you solve it: onContentChange(() => this._queueParse());
onTokenChange(() => this._queueParse());
_queued = false
_queueParse() {
if (!this._queued) {
queueMicrotask(() => this._parse());
this.queued = true;
}
} That will make
What confused me a little is why it wasn't essentially instant when I was just typing a non-bracket character. I didn't look into how the algorithm works or dig very deep into the code as I'm sure you know what you're doing there, I'm more interested in ensuring it doesn't waste time running twice in a single task and whether this can be deferred to shortly after text is rendered. |
Outcomes from our meeting:
vscode/src/vs/editor/common/model/bracketPairsTextModelPart/bracketPairsTree/bracketPairsTree.ts Lines 85 to 113 in 00b54ae
|
@Tyriar can you verify this issue? |
I do see it happening twice on a single keypress, but one of them is delayed until stick scroll renders which occurs after |
Part of #161622
Bracket pair parsing appears to happen twice on a single keypress as it happens when content changes and when tokenization happens. Typically on simple input "cheap" tokenization runs in the same task:
Consider using a microtask to execute the parsing at the end of the task a single time (which may get deferred to later depending on the outcome of #163235), rather than eagerly during the content changed event. I haven't looked much at the code but could we do bracket matching more incrementally so it's not taking several milliseconds?
The impact of this running twice is that input latency is pushed out several milliseconds on lower end/average hardware.
The text was updated successfully, but these errors were encountered: