The desktop becomes laggy when an external monitor is plugged in

I’m using Ubuntu 22.04 and nvidia-driver-525. The desktop I’m using is ubuntu:GNOME.

I’m using a Legion Y9000X laptop, and it is connected to an external gpu dock of 2070 super. My laptop only has an intergrated Intel gpu. When I plugged the external monitor to the laptop (integrated gpu), everything is working smoothly. The desktop also works smoothly when no external monitor is plugged in. However, when I plugged the external monitor to the gpu dock under ubuntu:GNOME desktop, the desktop becomes very laggy. When I run nvidia-smi, it seems that the gnome is not using the nvidia gpu.

I tried to switch the desktop to xorg, but it gets stuck at the login page.

However, in Windows, everything is smooth when I plugged the external monitor to the gpu dock.

Is there any solution to this?