wez / wezterm

A GPU-accelerated cross-platform terminal emulator and multiplexer written by @wez and implemented in Rust
https://wezfurlong.org/wezterm/
Other
17.52k stars 787 forks source link

High CPU Usage #2665

Open sandikata opened 2 years ago

sandikata commented 2 years ago

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

Linux X11

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

Mutter

WezTerm version

wezterm 20221023-205047-43f2265e

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

While working with multiple opened tabs, the CPU usage is insane, and it begins with lag. I cannot catch what is causing this.

To Reproduce

Open multiple tabs and run multiple tasks with thousands of lines output (like building or reading log files).

Configuration

wezterm.lua.zip

local wezterm = require 'wezterm'
local act = wezterm.action

wezterm.on('update-right-status', function(window, pane)
  window:set_right_status(window:active_workspace())
end)

return {
  font = wezterm.font_with_fallback {
    { family = 'Jetbrains Mono NL', weight = 'Regular' },
    { family = 'Terminus', weight = 'Bold' },
    'Noto Color Emoji',
  },
    font_size = 12.0,
    freetype_load_target = 'Light',
    freetype_render_target = 'HorizontalLcd',

    color_scheme_dirs = { os.getenv("HOME") .. "/.config/wezterm/colors/" },
    color_scheme = "Relaxed",

    term = "wezterm",

    front_end = "OpenGL",

    max_fps = 165,

    window_background_opacity = 0.98,

    -- initial_cols = 255,
    -- initial_rows = 50,

    scrollback_lines = 10000,

    enable_scroll_bar = true,

    use_fancy_tab_bar = true,

    tab_bar_at_bottom = true,

    window_frame = {
    -- The font used in the tab bar.
    -- Roboto Bold is the default; this font is bundled
    -- with wezterm.
    -- Whatever font is selected here, it will have the
    -- main font setting appended to it to pick up any
    -- fallback fonts you may have used there.
    font = wezterm.font { family = 'Roboto', weight = 'Bold' },

    -- The size of the font in the tab bar.
    -- Default to 10. on Windows but 12.0 on other systems
    font_size = 12.0,

    -- The overall background color of the tab bar when
    -- the window is focused
    active_titlebar_bg = '#333333',

    -- The overall background color of the tab bar when
    -- the window is not focused
    inactive_titlebar_bg = '#333333',
  },

  colors = {
    tab_bar = {
      -- The color of the inactive tab bar edge/divider
      inactive_tab_edge = '#575757',
    },
  },

  inactive_pane_hsb = {
  saturation = 0.9,
  brightness = 0.8,
  },

-- Split vertical current pane
keys = {
    -- This will create a new split and run your default program inside it
    {
      key = '"',
      mods = 'CTRL|SHIFT|ALT',
      action = wezterm.action.SplitVertical { domain = 'CurrentPaneDomain' },
    },
  },

-- Split horizontal current pane
  keys = {
    -- This will create a new split and run your default program inside it
    {
      key = '%',
      mods = 'CTRL|SHIFT|ALT',
      action = wezterm.action.SplitHorizontal { domain = 'CurrentPaneDomain' },
    },
  },

-- Zoom pane
    keys = {
    {
      key = 'Z',
      mods = 'CTRL|SHIFT',
      action = wezterm.action.TogglePaneZoomState,
    },
  },

-- Mouse cursor
  default_cursor_style = 'BlinkingUnderline',
  cursor_blink_rate = 300,

-- Visual Bell Screen Blink
  visual_bell = {
    fade_in_function = 'EaseIn',
    fade_in_duration_ms = 150,
    fade_out_function = 'EaseOut',
    fade_out_duration_ms = 150,
  },
  colors = {
    visual_bell = '#202020',
  },

-- Visual Bell Mouse Flare
--   visual_bell = {
--    fade_in_duration_ms = 75,
--    fade_out_duration_ms = 75,
--    target = 'CursorColor',
--  },

  keys = {
    {
      key = '0',
      mods = 'CTRL',
      action = wezterm.action.ResetFontAndWindowSize,
    },
  },

}

Expected Behavior

To work without insane CPU usage and insane lag (like it works on non GPU accelerated terminal emulators).

Logs

Debug Overlay
wezterm version: 20221023-205047-43f2265e
OpenGL version: AMD Radeon RX 6750 XT (navi22, LLVM 15.0.3, DRM 3.48, 6.0.1-gentoo) 4.6 (Compatibility Profile) Mesa 22.2.2
Enter lua statements or expressions and hit Enter.
Press ESC or CTRL-D to exit
16:48:40.319 INFO wezterm_gui::termwindow > clicking https://lifehacker.com/5837769/make-sure-your-partitions-are-correctly-aligned-for-optimal-solid-state-drive-performance
17:14:38.961 INFO wezterm_gui::termwindow > clicking https://github.com/nvbn/thefuck
18:05:05.103 INFO wezterm_gui::termwindow > clicking https://sindresorhus.com/caprine
18:16:15.020 INFO wezterm_gui::termwindow > clicking https://bugs.gentoo.org/715114

Anything else?

No response

sandikata commented 2 years ago

Снимка от 2022-10-25 09-19-56

sandikata commented 2 years ago

That's even without any tasks on it.

wez commented 2 years ago

Please capture a terminal recording:

*** Finished recording to /var/tmp/wezterm-recording-sF6B3u.cast.txt

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.

sandikata commented 2 years ago

Hello, There's a record.

wezterm-recording-Mplwz1.cast.txt

sandikata commented 1 year ago

Hello,

Is there something new ?

Regards.

wez commented 1 year ago

In the past day or so I pushed a couple of changes that should help with this; can you try the latest nightly build?

sandikata commented 1 year ago

wezterm 20221103-195702-40e08faf

If that't the latest commit i am already with it, and there's no difference.

sandikata commented 1 year ago

commit 30daed40b3b4e699e86e10875cd83bdc78b5e55d (grafted, HEAD -> main, origin/main, origin/HEAD) Author: Wez Furlong wez@wezfurlong.org Date: Mon Nov 14 23:11:02 2022 -0700

reduce size of BoxedQuad by 2/3

Since we're no longer tied to contiguous Vertex slices, we can
record the Quad data used for HeapQuadAllocator in a smaller structure,
so that's what this does.

It reduces the per-Quad storage from 272 bytes down to 84 bytes,
which helps with overall memory usage: the default cache size is 1024
lines worth of quads, so this can add up to multiple MB of RAM.

refs:  https://github.com/wez/wezterm/issues/2626

lines 1-15/15 (END)

from git log, i havent restarted yet wezterm, let me test, and will report.

wezterm -V wezterm 20221114-231102-30daed40

sandikata commented 1 year ago

Well, reporting now. No change.

wezterm-recording-XeLs27.cast.txt

wez commented 1 year ago

please remove max_fps = 165 from your config

sandikata commented 1 year ago

That's the refresh rate of my monitor.

sandikata commented 1 year ago

But anyway with or without it cpu load is insane.

wez commented 1 year ago

I use this to replay your recording with the default settings (modulo, adjusting for your window size):

time wezterm -n --config initial_rows=59 --config initial_cols=254 --config font_size=8  start -- wezterm replay ~/Downloads/wezterm-recording-XeLs27.cast.txt

and the CPU utilization is only ~2%, so we're missing something. Can you try running it the same way and see if the CPU is still high?

sandikata commented 1 year ago

https://cloud.aleksandrov-bg.com/s/aRzToTYnPLeztYN

Check on this video record. No matter, it just uses CPU and lagging.

$ time wezterm -n --config initial_rows=59 --config initial_cols=254 --config font_size=13 start -- wezterm replay /tmp/wezterm-recording-XeLs27.cast.txt 18:50:45.864 WARN wezterm_term::terminalstate > unhandled DecPrivateMode SetDecPrivateMode(Unspecified(1015)) 18:51:03.032 WARN wezterm_term::terminalstate > unhandled DecPrivateMode ResetDecPrivateMode(Unspecified(1015)) dhat: Total: 428,926,823 bytes in 1,083,542 blocks dhat: At t-gmax: 56,890,867 bytes in 439,690 blocks dhat: At t-end: 50,277,345 bytes in 424,762 blocks dhat: The data has been saved to dhat-heap.json, and is viewable with dhat/dh_view.html wezterm -n --config initial_rows=59 --config initial_cols=254 --config start 4,30s user 0,10s system 15% cpu 27,674 total

wez commented 1 year ago

The dhat output there suggests that wezterm was built with profiling enabled; that increases CPU utilization. Can you build it without that?

sandikata commented 1 year ago

Снимка от 2022-11-15 18-53-13

Just watch, now it's even worst, cannot switch between tabs.

wez commented 1 year ago

How are you building wezterm?

sandikata commented 1 year ago

https://wezfurlong.org/wezterm/install/source.html

cargo build --release --all-features

sandikata commented 1 year ago

https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=wezterm-git like in there.

wez commented 1 year ago

Please use cargo build --release like the docs suggest; turning on all features at once is not recommended!

sandikata commented 1 year ago

turning on all features at once is not recommended!

You just did it in your aur PKGBUILD ?

sandikata commented 1 year ago

Okay, i will check.

wez commented 1 year ago

I didn't write that :-/ I'll get it fixed

sandikata commented 1 year ago

image

Maintainer: wez ? Nevermind :)

Let me check with default features.

sandikata commented 1 year ago
rosen at aleksandrov in ~
$ time wezterm -n --config initial_rows=59 --config initial_cols=254 --config font_size=13  start -- wezterm replay /tmp/wezterm-recording-XeLs27.cast.txt
19:04:28.149  WARN   wezterm_term::terminalstate > unhandled DecPrivateMode SetDecPrivateMode(Unspecified(1015))
19:04:45.323  WARN   wezterm_term::terminalstate > unhandled DecPrivateMode ResetDecPrivateMode(Unspecified(1015))
wezterm -n --config initial_rows=59 --config initial_cols=254 --config  start  0,68s user 0,10s system 2% cpu 27,527 total

rosen at aleksandrov in ~

Well, that make sense. Let me work with it for some time and to report back.

Thank you for support.

bartlibert commented 1 year ago

For your information: I was using the same aur package and have now modified it to build in the same way as the official wezterm package in aur (cargo build --frozen --release --features distro-defaults), and (at least for me), the high CPU usage is gone.

correabuscar commented 1 year ago

I didn't write that :-/ I'll get it fixed

Maintainer: wez ? Nevermind :)

he's right tho, he didn't write that: https://aur.archlinux.org/cgit/aur.git/commit/PKGBUILD?h=wezterm-git&id=5926f26f6c29b7020a9cf1ccce0e6edb07721ce4

sorry, had to check as I was curious how'd that happen :) (no blame-placing intended)

As a side note, this issue is what prevented me from even giving wezterm a try when I was looking for a replacement for qterminal, and now I'm glad to know why it happened and I'll make sure to try it in the future, once the yml configuration of alacritty becomes too unbearable to work with (because of how easy it is to eg. misindent or forget to uncomment a parent node and have your setting be ignored).

towry commented 1 year ago

截屏2023-06-15 10 11 48


seems normal when using the default empty config.

my 'format-tab-title' callback is making it high cpu usage. my format-tab-title config: https://github.com/towry/dotfiles/blob/d23f10b7b8b6d84cda5afc4ec5c15061066ab58c/link/.config/wezterm/events.lua#L29

@wez Do you mind look at this what makes this callback consume so much cpu usage?