Skip to content

Fix excessive screen updates in progress indicators#14206

Merged
benhillis merged 8 commits intomasterfrom
copilot/fix-excessive-screen-updates
Feb 13, 2026
Merged

Fix excessive screen updates in progress indicators#14206
benhillis merged 8 commits intomasterfrom
copilot/fix-excessive-screen-updates

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 12, 2026

Summary of the Pull Request

Progress indicators were redrawing every 100ms regardless of whether the displayed value changed, causing screen flickering and unnecessary CPU/GPU overhead. This updates the draw logic in ConsoleProgressIndicator to cache the formatted string and only redraw when the displayed text actually changes.

PR Checklist

  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

The Issue

Progress indicators like those used in wsl --export poll every 100ms and unconditionally call UpdateProgress(), which erases and redraws the progress text. When the displayed value hasn't changed between polls, this causes:

  • Visible flickering in terminals
  • Continuous GPU activity for no-op redraws
  • Unnecessary CPU cycles

For example, with file size displays, if a file grew in sub-MB increments (e.g., from 1.1 MB to 1.9 MB), the progress would redraw multiple times even though the displayed value "(1 MB)" hadn't changed.

The Fix

Implemented string caching in ConsoleProgressIndicator::UpdateProgress() to compare the new progress message with the previously displayed one:

void ConsoleProgressIndicator::UpdateProgress(std::wstring&& Progress)
{
    if (!m_interactive)
    {
        return;
    }

    // Only update if the new progress message differs from the previous one
    if (Progress == m_progressMessage)
    {
        return;
    }

    for (auto i = 0; i < m_progressMessage.size(); i++)
    {
        fwprintf(stderr, L"\b \b");
    }

    fwprintf(stderr, L"%ls", Progress.c_str());
    m_progressMessage = std::move(Progress);
}

Key improvements:

  • General solution: Works for all callers of UpdateProgress(), not just file size displays
  • String-level comparison: Automatically handles all formatting variations (MB rounding, percentage truncation, etc.)
  • No caller changes needed: HandleConsoleProgressBar::UpdateFileSize() and other callers remain simple and don't need their own caching logic
  • Prevents duplicate output: Never prints the same string twice, regardless of how frequently callers invoke it

Validation Steps Performed

Requires manual testing on Windows:

  • Run wsl --export <distro> output.tar.xz --format tar.xz
  • Verify progress updates only when the displayed value changes (not every 100ms)
  • Verify no screen flickering
  • Verify reduced GPU/CPU usage during export
  • Verify other progress indicators (import, install, etc.) also benefit from the fix
Original prompt

This section details on the original issue you should resolve

<issue_title>wsl --export excessive screen updates</issue_title>
<issue_description>### Windows Version

Microsoft Windows [Version 10.0.26100.7840]

WSL Version

2.6.3.0

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

Kernel Version

6.6.87.2-1

Distro Version

Doesn't matter

Other Software

Microsoft terminal

Repro Steps

wsl --export .tar.xz --format tar.xz from a microsoft terminal session.

Example: wsl --export Ubuntu Ubuntu.tar.xz --format tar.xz
You should see some flickering of the end of the status line.
Also see an increase on GPU usage.

Expected Behavior

The progress indicator
Export in progress, this may take a few minutes. (#### MB)
The number should redraw when the number changes.

Actual Behavior

The number is being constantly redrawn. Many times per second. leading to unnecessary CPU/GPU overhead. If the number hasn't changed there is no reason to redraw it.

Diagnostic Logs

No response</issue_description>

<agent_instructions>Update progress bar drawing logic to only draw if the progress has changed.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits February 12, 2026 18:22
Only update progress display when file size actually changes, preventing
unnecessary screen redraws and reducing CPU/GPU overhead.

Co-authored-by: benhillis <17727402+benhillis@users.noreply.github.com>
Co-authored-by: benhillis <17727402+benhillis@users.noreply.github.com>
Co-authored-by: benhillis <17727402+benhillis@users.noreply.github.com>
Co-authored-by: benhillis <17727402+benhillis@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix excessive screen updates during wsl export Fix excessive screen updates in wsl --export progress indicator Feb 12, 2026
Copilot AI requested a review from benhillis February 12, 2026 18:24
Comment thread .gitignore Outdated
Co-authored-by: benhillis <17727402+benhillis@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR targets the wsl --export console progress indicator to reduce unnecessary redraws (and associated CPU/GPU usage + flicker) by skipping UpdateProgress() calls when the file size hasn’t changed.

Changes:

  • Add local state in HandleConsoleProgressBar::UpdateFileSize() to track the previous file size.
  • Only call ConsoleProgressIndicator::UpdateProgress() when the current size differs from the previous value.

Comment thread src/windows/common/HandleConsoleProgressBar.cpp Outdated
Comment thread src/windows/common/HandleConsoleProgressBar.cpp Outdated
When file size grows in sub-MB increments, comparing raw bytes causes
redraws even though the displayed MB value hasn't changed. Now we
calculate and compare the MB value directly, ensuring the progress
indicator only updates when the displayed value actually changes.

Also initialize previousSizeMB to -1 to ensure initial progress is
always shown (even when starting at 0 MB).

Co-authored-by: benhillis <17727402+benhillis@users.noreply.github.com>
Move the duplicate string check into ConsoleProgressIndicator::UpdateProgress()
itself. This provides a more general solution that prevents printing the same
string twice for any caller, not just the file size case. The comparison now
happens at the string level, which handles all formatting variations and makes
the fix more maintainable.

Co-authored-by: benhillis <17727402+benhillis@users.noreply.github.com>
Copilot AI changed the title Fix excessive screen updates in wsl --export progress indicator Fix excessive screen updates in progress indicators Feb 12, 2026
@benhillis benhillis merged commit 107fe52 into master Feb 13, 2026
1 check passed
@benhillis benhillis deleted the copilot/fix-excessive-screen-updates branch April 23, 2026 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wsl --export excessive screen updates

4 participants