[PR #6483] [MERGED] Recycle assorted rendering components to accelerate drawing #26701

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/6483
Author: @miniksa
Created: 6/12/2020
Status: Merged
Merged: 6/22/2020
Merged by: @undefined

Base: masterHead: dev/miniksa/recycle


📝 Commits (10+)

  • 9ad9b01 Recycle CustomTextLayouts between layout/render actions. This saves an awful lot of construction/destruction and memory allocation, especially with text that changes a lot (see: cacafire).
  • 942e7d5 order runs inplace with std::sort to dump the overhead of vector alloc, memory copy, swap.
  • bcb1ecd be fussy about our &s.
  • 7d0af68 code formatter.
  • bff43ae consolidate push/pop clip calls to be per-row.
  • 2f44fb9 eliminate cursor turds.
  • 6b34284 A little cleanup and static analysis fixes.
  • 65c2d93 dump explicit frame info, just stash the cursor info where we need it.
  • 1ab1dec Change DrawingContext constructor to initializer list pattern.
  • 8bd876b use optional instead of item and bool to ensure we don't end up in a torn state of remembering the rectangle dimensions when we think we popped the clip.

📊 Changes

6 files changed (+200 additions, -99 deletions)

View changed files

📝 src/renderer/dx/CustomTextLayout.cpp (+37 -15)
📝 src/renderer/dx/CustomTextLayout.h (+4 -1)
📝 src/renderer/dx/CustomTextRenderer.cpp (+50 -12)
📝 src/renderer/dx/CustomTextRenderer.h (+17 -10)
📝 src/renderer/dx/DxRenderer.cpp (+87 -59)
📝 src/renderer/dx/DxRenderer.hpp (+5 -2)

📄 Description

This saves an awful lot of construction/destruction and memory
allocation, especially with text that changes a lot (see: cacafire).

Three things:

  1. Recycling the text layouts. This holds onto the CustomTextLayout so
    all the things that don't change related to drawing targets and
    whatnot aren't freed and recreated every frame.
  2. Reordering the runs in place. This saves a vector
    allocation/copy/delete every time OrderRuns is called. They can be
    rearranged in place.
  3. Only clip once per row. This reduces the clip push/pop to only one
    time per row. Since we're always redrawing an entire row at a time,
    this saves a lot of alloc/free of the clip frame, dramatically
    reduces queued commands, and makes less work on the flush since
    clipping requires staging the drawing and then bringing it back to
    the main surface.

🔄 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/6483 **Author:** [@miniksa](https://github.com/miniksa) **Created:** 6/12/2020 **Status:** ✅ Merged **Merged:** 6/22/2020 **Merged by:** [@undefined](undefined) **Base:** `master` ← **Head:** `dev/miniksa/recycle` --- ### 📝 Commits (10+) - [`9ad9b01`](https://github.com/microsoft/terminal/commit/9ad9b01d53706a99a8ea85be7d4e32bb156f3c25) Recycle CustomTextLayouts between layout/render actions. This saves an awful lot of construction/destruction and memory allocation, especially with text that changes a lot (see: cacafire). - [`942e7d5`](https://github.com/microsoft/terminal/commit/942e7d53e7b868cbe5dada60e1fae44f1d6b0ddc) order runs inplace with std::sort to dump the overhead of vector alloc, memory copy, swap. - [`bcb1ecd`](https://github.com/microsoft/terminal/commit/bcb1ecd8be17881b6b5669f06d8e47fc6d44fa9a) be fussy about our &s. - [`7d0af68`](https://github.com/microsoft/terminal/commit/7d0af686619d6109b903cec1c8f90c776be61c14) code formatter. - [`bff43ae`](https://github.com/microsoft/terminal/commit/bff43ae9f7eb8b2f192e4bf27dd70b91f9e7c8a2) consolidate push/pop clip calls to be per-row. - [`2f44fb9`](https://github.com/microsoft/terminal/commit/2f44fb97dc41c388591132174bc90915d148f827) eliminate cursor turds. - [`6b34284`](https://github.com/microsoft/terminal/commit/6b34284c61bee1ca7310f5d5fbd92db77a50f589) A little cleanup and static analysis fixes. - [`65c2d93`](https://github.com/microsoft/terminal/commit/65c2d93d467991a346af43c9a0280d9f26e78135) dump explicit frame info, just stash the cursor info where we need it. - [`1ab1dec`](https://github.com/microsoft/terminal/commit/1ab1dec5a3231a575c3ac9ba5a31c1ce37e72100) Change DrawingContext constructor to initializer list pattern. - [`8bd876b`](https://github.com/microsoft/terminal/commit/8bd876b3a9aa77484abb7a8466662299e974cf87) use optional instead of item and bool to ensure we don't end up in a torn state of remembering the rectangle dimensions when we think we popped the clip. ### 📊 Changes **6 files changed** (+200 additions, -99 deletions) <details> <summary>View changed files</summary> 📝 `src/renderer/dx/CustomTextLayout.cpp` (+37 -15) 📝 `src/renderer/dx/CustomTextLayout.h` (+4 -1) 📝 `src/renderer/dx/CustomTextRenderer.cpp` (+50 -12) 📝 `src/renderer/dx/CustomTextRenderer.h` (+17 -10) 📝 `src/renderer/dx/DxRenderer.cpp` (+87 -59) 📝 `src/renderer/dx/DxRenderer.hpp` (+5 -2) </details> ### 📄 Description This saves an awful lot of construction/destruction and memory allocation, especially with text that changes a lot (see: cacafire). Three things: 1. Recycling the text layouts. This holds onto the `CustomTextLayout` so all the things that don't change related to drawing targets and whatnot aren't freed and recreated every frame. 2. Reordering the runs in place. This saves a vector allocation/copy/delete every time OrderRuns is called. They can be rearranged in place. 3. Only clip once per row. This reduces the clip push/pop to only one time per row. Since we're always redrawing an entire row at a time, this saves a lot of alloc/free of the clip frame, dramatically reduces queued commands, and makes less work on the flush since clipping requires staging the drawing and then bringing it back to the main surface. --- <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:38 +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#26701