Make sure all monitors are set at the same refresh rate, probably 60Hz.
This fixed the issue for me when using the laptop display along with a single non-Mac external display to extend the desktop.
My external monitor was set to 60Hz and my laptop display was set to ProMotion. I changed the laptop to 60Hz and the lagginess went away. I was shocked the solution was that easy, honestly.
I tried switching between USB-C and HDMI, using powered and non-powered monitor connections, and switching different USB ports, but none of that worked. I kept my external display at native resolution.
How did I diagnose this?
I was looking at the Activity Monitor for both GPU and CPU and noticed that when scrolling IntelliJ with just the laptop monitor, GPU usage for the app was much higher than when an external monitor was plugged in and I was scrolling on that (~50% vs. ~12%, respectively). I figured something was keeping IntelliJ from fully utilizing the GPU on an external monitor, so I tried syncing refresh rates across monitors (60Hz), and now I see GPU usage in the high 30's and the lagginess gone.
This is for a 16" M1 Max with 24 GPU cores running Ventura 13.4.1.