[PR #2937] Reduce InsertAttrRuns CPU usage #25163

Open
opened 2026-01-31 09:07:42 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/2937

State: closed
Merged: Yes


Summary of the Pull Request

Reduces CPU usage in ATTR_ROW::InsertAttrRuns.

References

#806

PR Checklist

  • Closes The new monospaced font (#806)
  • CLA signed. If not, go over here and sign the CLA
  • Tests added/passed
  • Requires documentation to be updated
  • I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan.

Detailed Description of the Pull Request / Additional comments

I myself have experienced the slow cursor movement described in #806 . I found one hotspot is in ATTR_ROW::InsertAttrRuns. It is called many times during screen redrawing. All those vector initializing and copying consumes lots of CPU cycles.

The idea is simple: exit as quickly as possible. The original author has already done this optimization when _list.size() is 1 or 2. I took a little further and aggresive way.

I added quick exit on these following condition

  • Insert single color that is the same as the left color:
AAAAABBBBBBBCCC
     ^
AAAAAABBBBBBCCC
  • Insert single color that is the same as surrouding ones
AAAAABBBBBBBCCC
       ^
AAAAABBBBBBBCCC

I didn't change the documentation cuz I wanna hear some feedback from the team before moving on.

Validation Steps Performed

Open .vimrc with vim and see for youself. It's not really "buttery smooth" but it it whole lot better. The CPU usage is dropped by about 30%.

**Original Pull Request:** https://github.com/microsoft/terminal/pull/2937 **State:** closed **Merged:** Yes --- ## Summary of the Pull Request Reduces CPU usage in `ATTR_ROW::InsertAttrRuns`. ## References #806 <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [X] Closes #806 * [X] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [ ] Tests added/passed * [ ] Requires documentation to be updated * [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. <!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments I myself have experienced the slow cursor movement described in #806 . I found one hotspot is in `ATTR_ROW::InsertAttrRuns`. It is called many times during screen redrawing. All those vector initializing and copying consumes lots of CPU cycles. The idea is simple: exit as quickly as possible. The original author has already done this optimization when `_list.size()` is 1 or 2. I took a little further and aggresive way. I added quick exit on these following condition * Insert single color that is the same as the left color: ```plaintext AAAAABBBBBBBCCC ^ AAAAAABBBBBBCCC ``` * Insert single color that is the same as surrouding ones ```plaintext AAAAABBBBBBBCCC ^ AAAAABBBBBBBCCC ``` I didn't change the documentation cuz I wanna hear some feedback from the team before moving on. <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed Open `.vimrc` with vim and see for youself. It's not really "buttery smooth" but it it whole lot better. The CPU usage is dropped by about 30%.
claunia added the pull-request label 2026-01-31 09:07:42 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#25163