Xorg excessive CPU usage on Nvidia drivers?

I recently decided to switch my main PC to Pop_OS. I am enjoying Linux so far but have noticed something weird. Apparently when moving windows or scrolling Xorg CPU usage spikes to 50-70%.

Now I don’t think this is expected behavior seeing as I am running the proprietary Nvidia drivers. glxinfo also shows that 2D acceleration is enabled. You would think a 1070 would be able to properly render GNOME, right? It’s a sad thing to see everything stutter because of high CPU usage.

Seeing as this is Pop_OS I would think everything is configured correctly for NVIDIA cards? Does anyone know a fix? Because I am out of luck and have been searching for the past few hours.

GTX 1070 (running at 1920x1200)
i7 4770
Nvidia driver 435.21
Gnome 3.34.1
Pop_OS! 19.10

Something something compositor problems…

Anyway I did try to replicate your concern and this is my machine
GTX 970 - 1920x1080 @60
i5 6600k
GNOME 3.28.4
Pop!_OS 18.04 LTS x86_64

This may be Xorg and your CPU showing its age. Lets hope Martin Wimpres fixes a lot of things in the 20.04 LTS the same way he did wonders for Ubuntu MATE.

As for the fixes, have you tried installing CPU freq as a gnome shell extension (or similar software)?

EDIT: I also recall Wendell saying something about cpufreqd

To correctly replicate the issue you would need Pop!_OS 19.10 which has significant updates to the gnome and mutter compositor code.

I have it installed myself by I just bypassed gnome and installed Plasma5 which is my preferred desktop, tho every now and again weird things do still happen with Xorg.

My only suggestion is try and enable triple buffer for gnome if it isn’t already enabled (xorg conf for nvidia drivers) and make sure its using that latest API for the compositor, (IE. plasma has option of OGL2 and 3.1) .

You should also test with the compositor disabled, perhaps install a alternative lightweight compositor to compare and test with vs the default one (mutter I believe)

I have the CPU Power Manager extension installed and just forced it to 100% clock speeds. This doesn’t seem to fix the issue.

Sadly I can’t try this because Mutter is so tightly integrated with GNOME that it would mean removing GNOME altogether. Now I have been thinking about switching to KDE, but I am afraid this will lead to some other bugs because of it not being as well integrated with Pop_OS. Do you have any experience with this?

EDIT:
Also I just had a fresh look at the issue and I am thinking that Spotify is causing the high CPU usage on Xorg. Just having the client open causes all application windows to stutter and Xorg CPU usage to spike when moving them. Closing Spotify immediately improves the situation.

The only stuttering I experience with Spotify closed is in Firefox (sometimes while scrolling or playing video). If I understand it correctly this is caused by the lack of hardware acceleration in Firefox which is to be fixed in the near future by the use of WebRender.

When running glxgears the CPU usage of Xorg also spikes while moving windows but doesn’t cause any major stuttering.

Why remove mutter? just use the --replace option that all compositors have, try xfce compositor.

I get what you mean but GNOME shell is the WM and compositor in one. Mutter is a part of the shell which, AFAIK, can’t be replaced.

Progress: I found out that the issue isn’t only caused by Spotify but rather by hardware accelerated content in general. Chromium with acceleration enabled causes the same stuttering and Firefox with WebRender forced as well.

Forcing full pipeline compositing in nvidia-settings seems to resolve the high CPU usage and makes moving windows a lot smoother. But apparently this is not something one should want because of decreased performance in games and input lag?

EDIT: How is running KDE on Pop!_OS?

I know that some people are going to scoff right now, but could you try using Wayland and reporting how it goes?
If you switch to KDE and then try Wayland, know that KDE’s implementation is still rough around the edges, unlike, at least from my experience, GNOME’s implementation. You will also probably need to install the Wayland-related packages separately (I’m not sure how that goes on Ubuntu nowadays, as I use Gentoo now, where you just add the “wayland” USE flag to make.conf and every package that can magically starts supporting Wayland after it is rebuilt).
If you are still running GNOME, you should be able to just log out, click on the cog below the username, select “something Wayland” and log back in. Just repeat the process, selecting a different option in the cog menu, to switch back to the X11 session. This is assuming that Wayland is installed by default, like it is on Ubuntu ever since Artful, or like on Fedora for who knows how long (hint: I’ve never used Fedora).

Regarding switching to KDE, my guess is that you simply remove all of the GNOME packages and install all of the KDE packages that you might need. You would need to use a tty (ctrl+alt+f[2, 3, …, 7]) for that though.

pretty sure I temp replaced mutter when I was using gnome with xfwm4 at one stage to test something, but maybe I’m remembering wrong. Might give it a test and see.

Wayland still does not work well with NVIDIA hardware, it can work but nvidia-settings and other things will fail.

Oh yeah… I am on an AMD laptop by the way.