Abysmal Nvidia GPU performance

I have an Asus Laptop with a hybrid GPU (Intel HD 520 & nvidia 940m). On a fresh install of Ubuntu 18.04 LTS, the iGPU performs as expected:

=======================================================     glmark2 2014.03+git20150611.fa71af2d =======================================================     OpenGL Information     GL_VENDOR:     Intel Open Source Technology Center     GL_RENDERER:   Mesa DRI Intel(R) HD Graphics 520 (Skylake GT2)      GL_VERSION:    3.0 Mesa 18.0.5 =======================================================  ...  =======================================================                                   glmark2 Score: 1380  =======================================================  

But the nvidia GPU performs poorly

=======================================================     glmark2 2014.03+git20150611.fa71af2d =======================================================     OpenGL Information     GL_VENDOR:     nouveau     GL_RENDERER:   NV118     GL_VERSION:    3.0 Mesa 18.0.5 =======================================================  ...  =======================================================                                   glmark2 Score: 292  ======================================================= 

Even worse performance with the proprietary driver:

=======================================================     glmark2 2014.03+git20150611.fa71af2d =======================================================     OpenGL Information     GL_VENDOR:     NVIDIA Corporation     GL_RENDERER:   GeForce 940M/PCIe/SSE2     GL_VERSION:    4.6.0 NVIDIA 390.116 =======================================================  ...  =======================================================                                   glmark2 Score: 165  ======================================================= 

The system runs fine if I use the iGPU but lags terribly with the nvidia gpu (firefox becomes a slideshow). Why is this happening?