Can we eliminate some of the IStateMachineEngine virtuals #16506

Open
opened 2026-01-31 05:14:12 +00:00 by claunia · 0 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?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#16506