Skip to content

Conversation

@teslae1
Copy link

@teslae1 teslae1 commented Dec 16, 2025

What this PR does / why we need it:
This is a pr to improve "typing while in insert mode" performance.
This is effectively a refactor since that the changes do not introduce any behavioural changes - only increase performance with existing behaviour.

The changes (per the commit messages) do the following:

  • skip sorting and shallow copy when there is only a single cursor
    • it is very often the case that there is only a single cursor
  • TypeInInsertMode action gets identified earlier (at iteration 6 instead of 11) at iteration that happens at base.ts line 267
    • this is a notable performance improvement - since several heap allocations and function calls are skipped foreach keystroke when in insert mode and "just typing".
  • o(1) lookup instead of o(n)
    • ensures o(1) performance for "isLiteralMode" lookup that is executed at every keystroke

Which issue(s) this PR fixes
No issues has been created that I know of - I just profiled the "typing while in insertmode" code-path and added low-impact optimizations.

Special notes for your reviewer:
Submitting this to contribute to this great extension and fix issues I experience myself.

…ad of 11) at iteration that happens at base.ts line 267 at time of writting 'for (const actionType of possibleActionsForMode)'. BackspaceInInsertMode was also moved as that has be handled before TypeInInsertMode.
}
}

@RegisterAction
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for moving the methods? It makes it more difficult to tell what changed

Mode.CommandlineInProgress,
Mode.SearchInProgressMode,
];
const literalModesMap = new Map<Mode, boolean>([
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use a Set rather than a Map?

: -1,
);
const cursorsToIterateOver =
vimState.cursors.length > 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you measured a performance difference with these changes? I want to be sure we're not prematurely optimizing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants