-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
ConPTY: Optimize SGR sequences by combining them into a single sequence #3016
Comments
One complication: we need to know the cancel-out combos (4, 24) and not emit crazy things that turn the state off and on in the same sequence. |
Apologies again that I'm commenting without fully understanding the context. What's the source of the data that you want to optimize this way?
If the source is some in-memory array of If the source is a sequence of SGRs, then { Would this particular case with cancel-out combos be a problem? I don't think so. However, it's easy to shoot yourself in the foot when you enter the territory of often misinterpreted and/or not (yet) supported escape sequences. E.g.
I'm afraid this sounds like the behavior would start depending on the timing of incoming data, and/or some heuristics, making it much harder to reproduce and debug potential issues. Also comes with additional code complexity, and along with it possibly additional runtime cost (detecting such situations), just to shave off 2 bytes on a local communication channel (if I understand the architecture correctly), and maybe (but not necessarily) make subsequent parsing of this data a tiny bit faster. Depending on many circumstances unbeknownst to me, it might result in an overall performance penalty, but even if that's not the case, it might easily come with pointless code complexity and engineering efforts not well spent – let alone the aforementioned problem of combining invalid (or just simply unknown, unrecognized) sequences into a valid one. } I hope my comment contained at least some usable parts :) |
@egmontkob This kinda gets at the core difference between ConPTY and a true pty. With a true pty it's more like a dumb pipe, the pty isn't generating any sequences of its own, it's just forwarding them along from client to terminal. With conpty however, that's not really the case. While yes, some applications (like WSL) are using VT sequences to interact with the "terminal", the majority of client apps are using the win32 Console API to interact with the "terminal". Conpty is then doing its own work to make sure that the state changed by the API is also kept in sync with the terminal, who's only reading a stream of VT sequences generated by conpty itself. In this particular case, as we're "rendering" a string of text (and colors) to the terminal (from conpty), we might decide that we need to both change the foreground to red and enable the underline. Currently, we'll add a Since conpty is fully in charge of the sequences generated here, I think we can pretty safely assume that we won't be accidentally combining a This would also be something that wouldn't happen in passthrough mode (#1173) at all, because in that scenario we would be acting as a dumb pipe. |
Thanks a lot for the clarification! I've just rewatched the relevant part of the WT announcement video to make sure I have the right architecture in mind. So the first "if" branch of my previous comment was the relevant one, i.e. I'm not sure how cancel-out combos like (4, 24) were feared to appear at all in the first place. Anyway, it's definitely something to remember during developing this feature, just in case. If optimizing matters, you might also do some guesswork whether sending the actual diff (turning off certain modes only) or building up from scratch after a reset is shorter; e.g. from bold+underlined+italic to italic should you do |
@egmontkob oh, you're totally right. I forgot to consider that if we're rendering from the buffer, we'll never have conflicting states stored. 😄 |
Other notes from the PR:
|
I wonder if there's an optimization we can take later that'll let us compress SGRs together when we know we're writing a bunch.
\x1b[40m
+\x1b[31m
+\x1b[4m
+\x1b[3m
=>\x1b[40;31;4;3m
?Originally posted by @DHowett-MSFT in #2917
The text was updated successfully, but these errors were encountered: