# Reduce GPU usage by activating VRR optimization only during high-rate input \(\#45369\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/b603372f44a60f8ed98ae95b36094582ead47b89)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: b603372f44a60f8ed98ae95b36094582ead47b89

Requested commit: b603372f44a60f8ed98ae95b36094582ead47b89

Commit: b603372f44a60f8ed98ae95b36094582ead47b89

Tree: 25bce3586f223ae38f9cb24b8065927a1632d374

Author: Antonio Scandurra

Committer: GitHub

## Message

```
Reduce GPU usage by activating VRR optimization only during high-rate input (#45369)

Fixes #29073

This PR reduces unnecessary GPU usage by being more selective about when
we present frames to prevent display underclocking (VRR optimization).

## Problem

Previously, we would keep presenting frames for 1 second after *any*
input event, regardless of whether it triggered a re-render. This caused
unnecessary GPU work when the user was idle or during low-frequency
interactions.

## Solution

1. **Only track input that triggers re-renders**: We now only record
input timestamps when the input actually causes the window to become
dirty, rather than on every input event.

2. **Rate-based activation**: The VRR optimization now only activates
when input arrives at a high rate (≥ 60fps over the last 100ms). This
means casual mouse movements or occasional keystrokes won't trigger
continuous frame presentation.

3. **Sustained optimization**: Once high-rate input is detected (e.g.,
during scrolling or dragging), we sustain frame presentation for 1
second to prevent display underclocking, even if input briefly pauses.

## Implementation

Added `InputRateTracker` which:
- Tracks input timestamps in a 100ms sliding window
- Activates when the window contains ≥ 6 events (60fps × 0.1s)
- Extends a `sustain_until` timestamp by 1 second each time high rate is
detected

Release Notes:

- Reduced GPU usage when idle by only presenting frames during bursts of
high-frequency input.
```

## Parents

- [7427924405dabda02cca87c24143f2d5f27eb433](https://git.cafe/gitcafe/zed/commit/7427924405dabda02cca87c24143f2d5f27eb433?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/b603372f44a60f8ed98ae95b36094582ead47b89?format=markdown)
