Can we eliminate some of the IStateMachineEngine virtuals #16509

Closed
opened 2026-01-31 05:14:19 +00:00 by claunia · 2 comments
Owner

Originally created by @j4james on GitHub (Jan 25, 2022).

Description of the new feature/enhancement

The IStateMachineEngine interface has a bunch of methods that influence how the StateMachine works. I'm referring to methods like ParseControlSequenceAfterSs3 and DispatchControlCharsFromEscape. They all return a boolean value that is always true for the InputStateMachineEngine, and false for the OutputStateMachineEngine.

If we just constructed the StateMachine with another parameter indicating whether it was input or output, we could reimplement those methods in the state machine itself with a simple field lookup, thus avoiding the expensive overhead of those virtual method calls.

Proposed technical implementation details (optional)

As described above.

Another idea I had, which may be a bit crazy, is to turn the StateMachine into a template, with separate instances for the input and output engines. That way you could avoid all of the virtual method calls, which could make quite a difference to the performance.

I realise that could bloat the code size a bit, but maybe the avoidance of virtuals will give the compiler more scope for optimising things, which could save a bit of space. I wouldn't expect it to be smaller, but the increase in size may not be that bad. Is it worth trying?

Originally created by @j4james on GitHub (Jan 25, 2022). # Description of the new feature/enhancement The `IStateMachineEngine` interface has a bunch of methods that influence how the `StateMachine` works. I'm referring to methods like `ParseControlSequenceAfterSs3` and `DispatchControlCharsFromEscape`. They all return a boolean value that is always true for the `InputStateMachineEngine`, and false for the `OutputStateMachineEngine`. If we just constructed the `StateMachine` with another parameter indicating whether it was input or output, we could reimplement those methods in the state machine itself with a simple field lookup, thus avoiding the expensive overhead of those virtual method calls. # Proposed technical implementation details (optional) As described above. Another idea I had, which may be a bit crazy, is to turn the `StateMachine` into a template, with separate instances for the input and output engines. That way you could avoid _all_ of the virtual method calls, which could make quite a difference to the performance. I realise that could bloat the code size a bit, but maybe the avoidance of virtuals will give the compiler more scope for optimising things, which could save a bit of space. I wouldn't expect it to be smaller, but the increase in size may not be _that_ bad. Is it worth trying?
Author
Owner

@zadjii-msft commented on GitHub (Jan 26, 2022):

Meh yea probably. These are likely artifacts from a time when we thought we should be more open to possible future implementations, but I think the perf gain is more important now. Let's do it

@zadjii-msft commented on GitHub (Jan 26, 2022): Meh yea probably. These are likely artifacts from a time when we thought we should be more open to possible future implementations, but I think the perf gain is more important now. Let's do it
Author
Owner

@ghost commented on GitHub (Feb 3, 2022):

:tada:This issue was addressed in #12277, which has now been successfully released as Windows Terminal Preview v1.13.10336.0.🎉

Handy links:

@ghost commented on GitHub (Feb 3, 2022): :tada:This issue was addressed in #12277, which has now been successfully released as `Windows Terminal Preview v1.13.10336.0`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v1.13.10336.0) * [Store Download](https://www.microsoft.com/store/apps/9n8g5rfz9xk3?cid=storebadge&ocid=badge)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#16509