[PR #3511] [MERGED] Throttle SetEvent call in render thread #25400

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/3511
Author: @skyline75489
Created: 11/10/2019
Status: Merged
Merged: 2/14/2020
Merged by: @miniksa

Base: masterHead: fix/setEventOverhead


📝 Commits (3)

📊 Changes

2 files changed (+26 additions, -1 deletions)

View changed files

📝 src/renderer/base/thread.cpp (+24 -1)
📝 src/renderer/base/thread.hpp (+2 -0)

📄 Description

Summary of the Pull Request

This is an attempt to reduce unnecessary SetEvent CPU overhead.

References

PR Checklist

  • Closes #xxx
  • 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. Issue number where discussion took place: #xxx

Detailed Description of the Pull Request / Additional comments

Redrawing is triggered intensively when terminal is under load. The code here indicates that the redraw call will be throttled:

94fc40ed31/src/renderer/base/renderer.cpp (L154)

Still, the SetEvent call itself stands out a 7% usage of CPU in Release build. Those SetEvent calls are mostly useless because most of them are invoked while the rendering thread is sleeping (for s_FrameLimitMilliseconds long).

图片

I've tried to guard all the useless calls with _fPainting flag, as in this PR. It works great for the CPU. But the rendering became noticeably sluggish.

I've figured that the rendering thread design is flawed in the perspective of this certain issue, probably also future unknown issues. Instead of being a thread that can be notified, it should behave more like a timer that invokes rendering opereation every s_FrameLimitMilliseconds. In this way, the rendering thread will be more focused on its own work without being distracted from others.

Maybe @egmontkob can provide us some insight about this.

Validation Steps Performed


🔄 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/3511 **Author:** [@skyline75489](https://github.com/skyline75489) **Created:** 11/10/2019 **Status:** ✅ Merged **Merged:** 2/14/2020 **Merged by:** [@miniksa](https://github.com/miniksa) **Base:** `master` ← **Head:** `fix/setEventOverhead` --- ### 📝 Commits (3) - [`8d1843f`](https://github.com/microsoft/terminal/commit/8d1843f75804540c90cfcaa2106b3947fc72432f) Throttle SetEvent call in render thread - [`722ba64`](https://github.com/microsoft/terminal/commit/722ba6456007f9d85ffbc32a3891683d7628b4ad) Change for review - [`cc1dbc0`](https://github.com/microsoft/terminal/commit/cc1dbc06e59678bbdfa459879fcebac5f7de8693) Atomic flag ### 📊 Changes **2 files changed** (+26 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/renderer/base/thread.cpp` (+24 -1) 📝 `src/renderer/base/thread.hpp` (+2 -0) </details> ### 📄 Description <!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request This is an attempt to reduce unnecessary `SetEvent` CPU overhead. <!-- Other than the issue solved, is this relevant to any other issues/existing PRs? --> ## References <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [ ] Closes #xxx * [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. Issue number where discussion took place: #xxx <!-- 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 Redrawing is triggered intensively when terminal is under load. The code here indicates that the redraw call will be throttled: https://github.com/microsoft/terminal/blob/94fc40ed31c0de050304248644458b21d0cce2e9/src/renderer/base/renderer.cpp#L154 Still, the `SetEvent` call itself stands out a 7% usage of CPU in Release build. Those `SetEvent` calls are mostly useless because most of them are invoked while the rendering thread is sleeping (for `s_FrameLimitMilliseconds` long). ![图片](https://user-images.githubusercontent.com/4710575/68544415-e9107300-03fd-11ea-8929-89e2ac7753eb.png) I've tried to guard all the useless calls with `_fPainting` flag, as in this PR. It works great for the CPU. But the rendering became noticeably sluggish. I've figured that the rendering thread design is flawed in the perspective of this certain issue, probably also future unknown issues. Instead of being a thread that can be notified, it should behave more like a *timer* that invokes rendering opereation every `s_FrameLimitMilliseconds`. In this way, the rendering thread will be more focused on its own work without being distracted from others. Maybe @egmontkob can provide us some insight about this. <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed --- <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:09:16 +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#25400