Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some TUI will flash all the time #2443

Closed
asorander opened this issue Aug 21, 2022 · 7 comments
Closed

Some TUI will flash all the time #2443

asorander opened this issue Aug 21, 2022 · 7 comments
Labels
bug Something isn't working fixed-in-nightly This is (or is assumed to be) fixed in the nightly builds.

Comments

@asorander
Copy link

What Operating System(s) are you seeing this problem on?

Linux X11

Which Wayland compositor or X11 Window manager(s) are you using?

Gnome 42.3 + Mutter

WezTerm version

20220807-113146-c2fee766

Did you try the latest nightly build to see if the issue is better (or worse!) than your current version?

Yes, and I updated the version box above to show the version of the nightly that I tried

Describe the bug

Some TUIs will flash whenever there is something changing on the screen. In the video below, I show a comparison between the same apps (Ncspot and the clock on ncmpcpp) running on Wezterm and Gnome Terminal, and the "flashing" isn't happening on Gnome Terminal. Also, it doesn't happen on Alacritty, so i don't think it's some gpu issue.

2022-08-21.16-07-36.mp4

To Reproduce

Just browse a list of musics on ncspot or open the clock on ncmpcpp.

Configuration

It also happens without a custom config file.

Expected Behavior

Do not flash on TUIs.

Logs

Debug Overlay
wezterm version: 20220807-113146-c2fee766
OpenGL version: NVIDIA GeForce GTX 1660/PCIe/SSE2 4.6.0 NVIDIA 515.65.01
Enter lua statements or expressions and hit Enter.
Press ESC or CTRL-D to exit
16:27:30.163 WARN wezterm_term::terminalstate > unhandled DecPrivateMode SetDecPrivateMode(Unspecified(1015))

Anything else?

No response

@asorander asorander added the bug Something isn't working label Aug 21, 2022
@wez
Copy link
Member

wez commented Aug 21, 2022

Please capture a terminal recording:

  • Launch wezterm. If possible, please use 80x24 for the terminal dimensions as it helps to keep things smaller and easier to manage.
  • Inside that terminal run wezterm record to start a recording session.
  • Run through your reproduction steps
  • Then type exit
  • You should see a message like:
*** Finished recording to /var/tmp/wezterm-recording-sF6B3u.cast.txt
  • Attach the file that it produced to this issue.

The file is an asciicast (compatible with https://asciinema.org/) and can also be replayed using wezterm replay.

The terminal recording allows me to replicate what is being sent to the terminal without requiring me to install the same applications as you and replicate your configuration for everything.

@wez wez added the waiting-on-op Waiting for more information from the original poster label Aug 21, 2022
@asorander
Copy link
Author

Please capture a terminal recording:

* Launch wezterm.  If possible, please use 80x24 for the terminal dimensions as it helps to keep things smaller and easier to manage.

* Inside that terminal run `wezterm record` to start a recording session.

* Run through your reproduction steps

* Then type `exit`

* You should see a message like:
*** Finished recording to /var/tmp/wezterm-recording-sF6B3u.cast.txt
* Attach the file that it produced to this issue.

The file is an asciicast (compatible with https://asciinema.org/) and can also be replayed using wezterm replay.

The terminal recording allows me to replicate what is being sent to the terminal without requiring me to install the same applications as you and replicate your configuration for everything.

Here's the output:

wezterm-recording-UBGaJu.cast.txt

This time I cleared my config file, leaving only the following lines:

local wezterm = require 'wezterm'
return {
  initial_rows = 24,
  initial_cols = 80,
}

@github-actions github-actions bot removed the waiting-on-op Waiting for more information from the original poster label Aug 21, 2022
@wez
Copy link
Member

wez commented Aug 21, 2022

What's happening here is that both of those programs are very poorly optimized when it comes to what they output; they are erasing a screen line by line before repainting the lines individually and in some cases, re-erasing the lines again before repainting them.

Because they output a fairly large chunk of redundant output at a time, and that data doesn't fit in a single buffer write, wezterm ends up painting the screen in between "logical" frames from the perspective of the application.

Ideally those programs would implement https://gist.github.com/christianparpart/d8a62cc1ab659194337d73e399004036 to explicitly indicate when they writing out the screen.

I can add some artificial latency in wezterm to increase the chances of recognizing those as a batch, but it will harm the performance of things like time cat bigfile "benchmarks". I will put that behind a configuration setting so that the degree of additional latency can be tuned.

@asorander
Copy link
Author

Oh, I see. I hope that they fix this kind of issue in the future on those apps...
Thank you very much for your time and for taking a look at it! :)

wez added a commit that referenced this issue Aug 21, 2022
It's not the first time that I've solved a problem by slowing things
down... in this situation, a couple of very inefficient TUI programs had
flickering outputs in wezterm because they were filling a buffer with a
bunch of spaces to erase a screen before sending the main body of their
updates in a subsequent buffer chunk. wezterm would render the
intervening partially blank frame and appear to flicker.

The resolution is to add a small delay (3ms by default) before sending
data to the terminal model. If the output is readable in that time
we'll accumulate it with the pending set of actions so that the
whole batch can be applied "more atomically".

Take care: `time cat bigfile` is sensitive to this, so we want to
keep the latency as small as possible, and we also want to avoid
accumulating actions and only flushing them at the end of the file.

We use the existing buffer size (~1MB) as a threshold: we bump
a count of the number of input bytes that resulted in the current
set of actions, and if that exceeds that buffer size we flush it.

refs: #2443
@wez wez added the fixed-in-nightly This is (or is assumed to be) fixed in the nightly builds. label Aug 21, 2022
@wez
Copy link
Member

wez commented Aug 21, 2022

This should be fixed now in main.

It typically takes about an hour before fixes are available as nightly builds for all platforms. Linux builds are the fastest to build and are often available within about 20 minutes. Windows and macOS builds take a bit longer.

Please take a few moments to try out the fix and let me know how that works out. You can find the nightly downloads for your system in the wezterm installation docs.

If you prefer to use packages provided by your distribution or package manager of choice and don't want to replace that with a nightly download, keep in mind that you can download portable packages (eg: a .dmg file on macOS, a .zip file on Windows and an .AppImage file on Linux) that can be run without permanently installing or replacing an existing package, and can then simply be deleted once you no longer need them.

If you are eager and can build from source then you may be able to try this out more quickly.

@asorander
Copy link
Author

Just tried the nightly AppImage, and now it's working perfectly! No more issues in any app that I've tested. :)

Thank you very much!

@wez wez closed this as completed Aug 21, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2023

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working fixed-in-nightly This is (or is assumed to be) fixed in the nightly builds.
Projects
None yet
Development

No branches or pull requests

2 participants