Lag spikes when running games using the NVIDIA GPU on an Optimus laptop

Hi, I finally got NVIDIA drivers to work on my Optimus laptop (they didn’t work on 22.11, I’m now on unstable), but I’m getting lag spikes every 30 seconds or so when running any game using the dGPU.

Using MangoHUD and Lutris, I can see that the, when a lag spike occurs, the GPU usage plummets (it would drop from 100% to <15%) and CPU usage spikes on all cores.

Here’s the relevant part of my configuration.nix:

  services.xserver.videoDrivers = [ "nvidia" ];
  hardware.opengl.enable = true;
  hardware.opengl.driSupport = true;
  hardware.opengl.driSupport32Bit = true;
  services.switcherooControl.enable = true;
  boot.blacklistedKernelModules = [ "nouveau" ];

  hardware.nvidia = {
    package = config.boot.kernelPackages.nvidiaPackages.beta;
    modesetting.enable = true;
    nvidiaSettings = true;

    prime = {
      offload = {
        enable = true;
        enableOffloadCmd = true;

      intelBusId = "PCI:0:0:2:0";
      nvidiaBusId = "PCI:0:1:0:0";

I use GNOME + Wayland and switching to X11 isn’t really an option, as I have a HiDPI screen on my laptop and a “normal” 1080p external monitor. I also make use of Waydroid for development.
(And also GNOME on Xorg refuses to launch).

Could this be an overheating or throttling issue? (I usually use one of those laptop stands with fans)

UPDATE: It’s probably due to thermal throttling; the GPU seems like it’s trying to not climb about 80° C (when it does, the lag spikes happen). Won’t mark as solved until I get the chance to test with my laptop cooler stand.

What appears to have fixed it is commenting out the line services.thermald.enable = true. I accidentally didn’t create this post under the “Help” thread, so I cannot set this as SOLVED.

Odd, wonder what the thermald community would say about this. I’ve only heard of it improving performance. I saw this thread upstream, maybe also try the flag suggested there: thermald effects NVIDIA GPU throttling · Issue #300 · intel/thermal_daemon · GitHub

I’ve moved the topic for you if you want to mark it as solved.

1 Like