[PR #6420] Improve perf by avoiding vector reallocation in renderer clusters and VT output graphics options #26677

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

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

State: closed
Merged: Yes


Summary of the Pull Request

Caches vectors in the class and uses a new helper to opportunistically shrink/grow as viewport sizes change in order to save performance on alloc/free of commonly used vectors.

PR Checklist

  • Scratches a perf itch.
  • I work here.
  • wil tests added
  • No add'l doc.
  • Am core contributor.

Detailed Description of the Pull Request / Additional comments

Two fixes:

  1. For outputting lots of text, the base renderer class spent a lot of time allocating and freeing and reallocating the Cluster vector that adapts the text buffer information into render clusters. I've now cached this vector in the base render class itself and I shrink/grow it based on the viewport update that happens at the top of every frame. To prevent too much thrashing in the downward/shrink direction, I wrote the til::manage_vector helper that contains a threshold to only shrink if it asks for small enough of a size relative to the existing one. I used 80% of the existing size as the threshold for this one.
  2. For outputting lots of changing colors, the VT graphics output engine spent a bunch of time allocating and reallocating the vector for GraphicsOptions. This one doesn't really have a predictable size, but I never expect it to get extremely big. So I just held it in the base class.

Validation Steps Performed

  • Ran the til unit test
  • Checked render cluster vector time before/after against big.txt from Tests aren't executing in CI (#1064)
  • Checked VT graphics output vector time before/after against cacafire
Case Before After
big.txt image image
cacafire image image
**Original Pull Request:** https://github.com/microsoft/terminal/pull/6420 **State:** closed **Merged:** Yes --- ## Summary of the Pull Request Caches vectors in the class and uses a new helper to opportunistically shrink/grow as viewport sizes change in order to save performance on alloc/free of commonly used vectors. ## PR Checklist * [x] Scratches a perf itch. * [x] I work here. * [x] wil tests added * [x] No add'l doc. * [x] Am core contributor. ## Detailed Description of the Pull Request / Additional comments Two fixes: 1. For outputting lots of text, the base renderer class spent a lot of time allocating and freeing and reallocating the `Cluster` vector that adapts the text buffer information into render clusters. I've now cached this vector in the base render class itself and I shrink/grow it based on the viewport update that happens at the top of every frame. To prevent too much thrashing in the downward/shrink direction, I wrote the `til::manage_vector` helper that contains a threshold to only shrink if it asks for small enough of a size relative to the existing one. I used 80% of the existing size as the threshold for this one. 2. For outputting lots of changing colors, the VT graphics output engine spent a bunch of time allocating and reallocating the vector for `GraphicsOptions`. This one doesn't really have a predictable size, but I never expect it to get extremely big. So I just held it in the base class. ## Validation Steps Performed * [x] Ran the til unit test * [x] Checked render cluster vector time before/after against `big.txt` from #1064 * [x] Checked VT graphics output vector time before/after against `cacafire` Case | Before | After ---|---|---| `big.txt` | ![image](https://user-images.githubusercontent.com/18221333/84088632-cbaa8400-a9a1-11ea-8932-04b2e12a0477.png) | ![image](https://user-images.githubusercontent.com/18221333/84088996-b6822500-a9a2-11ea-837c-5e32a110156e.png) `cacafire` | ![image](https://user-images.githubusercontent.com/18221333/84089153-22648d80-a9a3-11ea-8567-c3d80efa16a6.png) | ![image](https://user-images.githubusercontent.com/18221333/84089190-34463080-a9a3-11ea-98e5-a236b12330d6.png)
claunia added the pull-request label 2026-01-31 09:17:30 +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#26677