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

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/6420
Author: @miniksa
Created: 6/9/2020
Status: Merged
Merged: 6/10/2020
Merged by: @undefined

Base: masterHead: dev/miniksa/perf


📝 Commits (3)

  • 6937a8e Cache the vector for clusters and manage its size based on the viewport to save a ton of alloc/dealloc work.
  • 88b3e25 hold vt graphics options vector in class to save alloc/realloc/free time.
  • 13208eb speeling

📊 Changes

9 files changed (+82 additions, -10 deletions)

View changed files

📝 src/inc/til.h (+20 -0)
📝 src/renderer/base/renderer.cpp (+13 -7)
📝 src/renderer/base/renderer.hpp (+3 -0)
📝 src/terminal/parser/OutputStateMachineEngine.cpp (+5 -3)
📝 src/terminal/parser/OutputStateMachineEngine.hpp (+1 -0)
src/til/ut_til/BaseTests.cpp (+36 -0)
📝 src/til/ut_til/sources (+1 -0)
📝 src/til/ut_til/til.unit.tests.vcxproj (+1 -0)
📝 src/til/ut_til/til.unit.tests.vcxproj.filters (+2 -0)

📄 Description

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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/6420 **Author:** [@miniksa](https://github.com/miniksa) **Created:** 6/9/2020 **Status:** ✅ Merged **Merged:** 6/10/2020 **Merged by:** [@undefined](undefined) **Base:** `master` ← **Head:** `dev/miniksa/perf` --- ### 📝 Commits (3) - [`6937a8e`](https://github.com/microsoft/terminal/commit/6937a8e7cdcb6513f7787a01ea5ebccbda538769) Cache the vector for clusters and manage its size based on the viewport to save a ton of alloc/dealloc work. - [`88b3e25`](https://github.com/microsoft/terminal/commit/88b3e2565c22011f3ad9db80a14cb5eb1ac2fd26) hold vt graphics options vector in class to save alloc/realloc/free time. - [`13208eb`](https://github.com/microsoft/terminal/commit/13208eb238d15b2c9ad9d6a8ec7f4d782f47e9aa) speeling ### 📊 Changes **9 files changed** (+82 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `src/inc/til.h` (+20 -0) 📝 `src/renderer/base/renderer.cpp` (+13 -7) 📝 `src/renderer/base/renderer.hpp` (+3 -0) 📝 `src/terminal/parser/OutputStateMachineEngine.cpp` (+5 -3) 📝 `src/terminal/parser/OutputStateMachineEngine.hpp` (+1 -0) ➕ `src/til/ut_til/BaseTests.cpp` (+36 -0) 📝 `src/til/ut_til/sources` (+1 -0) 📝 `src/til/ut_til/til.unit.tests.vcxproj` (+1 -0) 📝 `src/til/ut_til/til.unit.tests.vcxproj.filters` (+2 -0) </details> ### 📄 Description ## 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:17:29 +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#26672