JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.17k stars 1.11k forks source link

Laggy UI on Linux (Ubuntu) with two connected displays #23

Closed igordmn closed 3 years ago

igordmn commented 3 years ago

Following: https://github.com/JetBrains/compose-jb/pull/10#issuecomment-713038689

P.S. I checked that examples/todoapp works fine on my PC/Windows and MacBook: animations/resizing seems aren't laggy (on Windows there are some issues with performance, but they are not always visible)

arkivanov commented 3 years ago

I'm not sure what was the issue, but now it is suddenly fine. It does not lag on my machine.

arkivanov commented 3 years ago

Found the reason. It only lags when a secondary monitor is connected. All other apps are fine.

olonho commented 3 years ago

Could be Open GL drivers issue.

olonho commented 3 years ago

Interesting, so not sure if we could do much on Compose side.

ToxicBakery commented 3 years ago

I'm on Ubunutu as well and compose probably runs at around 15-20 fps. Using nvidia drivers with a 1080ti and a single ultrawide monitor. I ran the CEF demo and interestingly CEF has pretty good frame rates, I can even watch Youtube inside the CEF without issue, but compose continues to have poor frame rate.

Any debugging you would like done that might help highlight what the issue is? Adding some system information to minimize any back and forths on this.

$ uname -a
Linux ubuntu-desktop 5.4.0-52-generic #57-Ubuntu SMP Thu Oct 15 10:57:00 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.1 LTS
Release:    20.04
Codename:   focal
$ nvidia-smi 
Tue Nov 10 08:41:46 2020       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 435.21       Driver Version: 435.21       CUDA Version: 10.1     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 108...  Off  | 00000000:42:00.0  On |                  N/A |
| 16%   55C    P0    66W / 250W |    894MiB / 11175MiB |      6%      Default |
+-------------------------------+----------------------+----------------------+
Dominaezzz commented 3 years ago

I experience lag only when I focus on an OutlinedTextField. Even mouse starts to stutter. (Arch Linux & i3)

Dominaezzz commented 3 years ago

I don't think this has to do with rendering (OpenGL) issues. I think this has to do with (some kind of) event handling. I only get lag when there's some sort of animation involved.

kevincianfarini commented 3 years ago

Which display server is being used? X11, XWayland, or native wayland?

Does the issue persist if you switch sessions to another display server?

igordmn commented 3 years ago

With two connected monitors, this code:

wrapped.graphicsConfiguration.device.displayMode.refreshRate

can be very slow (50-100ms). We call it on every frame.

We will try to switch to system vsync instead of this in https://github.com/JetBrains/compose-jb/issues/137

petitJAM commented 3 years ago

I'm getting similar issues running on Ubuntu 20.04 on X11 with multiple monitors. Performance does get worse when a TextField is displayed. I hadn't realized that multiple monitors was the problem until I found this issue, but then I tried it without them attached and it does seem to work smoothly.

I haven't tried on Wayland, but I do have that installed, so I could give it a go soon.

$ uname -a
Linux bryyo 5.4.0-58-generic #64-Ubuntu SMP Wed Dec 9 08:16:25 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.1 LTS
Release:    20.04
Codename:   focal
$ nvidia-smi 
Tue Dec 29 08:52:29 2020       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 450.80.02    Driver Version: 450.80.02    CUDA Version: 11.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  Quadro M2200        Off  | 00000000:01:00.0 Off |                  N/A |
| N/A   47C    P0    N/A /  N/A |    743MiB /  4043MiB |     26%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

I've seen the same thing in both of these projects, so I don't think it's related to any specific code that I've written, but just in case it helps: https://github.com/petitJAM/compose-test-app https://github.com/petitJAM/Avidity

Janrupf commented 3 years ago

Same issue here, I to be honest have not tested disconnecting monitors, but I will assume that my 3 connected monitors are the issue. Running the demo app and then clicking the button lags the entire desktop for about 2 seconds.

Its just this example code:

fun main() = Window {
    var text by remember { mutableStateOf("Hello, World!") }

    MaterialTheme {
        Button(onClick = {
            text = "Hello, Desktop!"
        }) {
            Text(text)
        }
    }
}

This should be enough to fully reproduce the issue. I want to point out once again that it is enough to click the button in the example and everything lags.

System info:

OS: Arch Linux x86_64
Kernel: 5.10.3-arch1-1
Resolution: 1920x1080, 1920x1080, 1920x1080
WM: i3-gaps
CPU: AMD Ryzen Threadripper 1950X (32) @ 3.400GHz
GPU: NVIDIA GeForce GTX 1080
Memory: 14737MiB / 64223MiB

NVIDIA smi:

Fri Jan  8 19:30:11 2021       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 455.45.01    Driver Version: 455.45.01    CUDA Version: 11.1     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  GeForce GTX 1080    Off  | 00000000:09:00.0  On |                  N/A |
|  0%   58C    P5    24W / 240W |    994MiB /  8111MiB |     18%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1345      G   /usr/lib/Xorg                     657MiB |
|    0   N/A  N/A      1453      G   ...AAAAAAAA== --shared-files       67MiB |
|    0   N/A  N/A      2479      G   ...AAAAAAAAA= --shared-files       33MiB |
|    0   N/A  N/A     13521      G   kitty                               3MiB |
|    0   N/A  N/A     15561      G   ./ts3client_linux_amd64             2MiB |
|    0   N/A  N/A     35932      G   picom                               2MiB |
|    0   N/A  N/A     35934      G   .../xscreensaver/glslideshow       50MiB |
|    0   N/A  N/A     35935      G   .../xscreensaver/glslideshow       50MiB |
|    0   N/A  N/A     35936      G   .../xscreensaver/glslideshow       50MiB |
|    0   N/A  N/A     48521      G   .../java-14-openjdk/bin/java        7MiB |
+-----------------------------------------------------------------------------+

Killing the compositor and other OpenGL applications doesn't change anything.

Spationaute commented 3 years ago

I got the same problem:

 OS: Ubuntu 20.04 focal
 Kernel: x86_64 Linux 5.4.0-60-generic
 Resolution: 3840x1080
 DE: GNOME 3.36.4
 CPU: Intel Core i7-8750H @ 12x 4.1GHz [62.0°C]
 GPU: GeForce GTX 1060
 RAM: 11675MiB / 31804MiB
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.32.03    Driver Version: 460.32.03    CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  GeForce GTX 1060    Off  | 00000000:01:00.0  On |                  N/A |
| N/A   58C    P0    23W /  N/A |    349MiB /  6078MiB |      8%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1627      G   /usr/lib/xorg/Xorg                251MiB |
|    0   N/A  N/A      2095      G   /usr/bin/gnome-shell               88MiB |
|    0   N/A  N/A     45660      G   ...m/java-15-oracle/bin/java        5MiB |
+-----------------------------------------------------------------------------+
igordmn commented 3 years ago

Problem with two displays should be fixed soon.

There is prebuilt version for testing: 0.0.0-vsync-build30

P.S. I discovered a new performance issue with maximized window, not related to this issue.

Janrupf commented 3 years ago

Its fixed, really cool!

Spationaute commented 3 years ago

Sweet, I changed to the testing version and it doesn't lag anymore! Good job!

tth05 commented 3 years ago

When will this be merged into a full release? I'm having the same issue, 15 FPS or lower, disconnecting one monitor doesn't help. The custom prebuilt version fixes it though.

igordmn commented 3 years ago

When will this be merged into a full release?

I hope this week or at the beginning of the next. The changes are on a review now: https://android-review.googlesource.com/c/platform/frameworks/support/+/1535152 https://android-review.googlesource.com/c/platform/frameworks/support/+/1534675

igordmn commented 3 years ago

Should be fixed in 0.3.0-build146.

sergeyampo commented 2 years ago

Spent so many hours finding how to improve UI performance on Ubuntu 21 with Nvidia graphic card. Tried literally everything but what does help is: sudo nvidia-settings image