# High CPU usage when window is on fullscreen

**URL:** <https://discourse.glfw.org/t/high-cpu-usage-when-window-is-on-fullscreen/1859>\
**Category:** support\
**Created:** [May 17, 2021, 2:44am UTC](https://discourse.glfw.org/t/high-cpu-usage-when-window-is-on-fullscreen/1859 "2021-05-17T02:44:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eboru](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/eboru/32/521_2.png) [@Eboru](https://discourse.glfw.org/u/Eboru)\
**Post date:** [May 17, 2021, 2:44am UTC](https://discourse.glfw.org/t/high-cpu-usage-when-window-is-on-fullscreen/1859/1 "2021-05-17T02:44:00Z")

</div>

I’m concerned about a high CPU usage when the window is set to fullscreen via glfwCreateWindow(mode-\>width, mode-\>height, “ex”, glfwGetPrimaryMonitor(), nullptr);

Windowed performance is much more lower (as expected) via  
glfwCreateWindow(mode-\>width, mode-\>height, “ex”, nullptr, nullptr);

In both swap interval was set to 1.

It seems to be some external code according to CPU usage viewer

 ![glfw](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/25916c8b04ded8fec10ee5fca5513500bec6606a.png)

I’d like to know if this is an expected behaviour of glfw, a bug, or something else.

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [May 17, 2021, 10:16am UTC](https://discourse.glfw.org/t/high-cpu-usage-when-window-is-on-fullscreen/1859/2 "2021-05-17T10:16:31Z")

</div>

High single core CPU usage in a graphics application is often due to low GPU load (so the application is not constrained by the GPU performance) and a [swap interval set to 0 (also known as no vertical sync/vsync)](https://www.glfw.org/docs/latest/group__context.html#ga6d4e0cdf151b5e579bd67f13202994ed) resulting in the main loop spinning.

The difference between windowed and fullscreen is potentially due to vsync being on by default for the windowed state.

To check this, try monitoring your frame rate and setting the `glfwSwapInterval` to 1 or 0 to see the difference. You can also control your frame rate using a sleep (different APIs on Posix/Windows) or using `glfwPollEvents` rather than `glfwWaitEvents` when you don’t need continuos updates but only need changes when the user performs an action.

---

<div class="post-metadata">

**Author:** ![Eboru](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/eboru/32/521_2.png) [@Eboru](https://discourse.glfw.org/u/Eboru)\
**Post date:** [May 17, 2021, 2:07pm UTC](https://discourse.glfw.org/t/high-cpu-usage-when-window-is-on-fullscreen/1859/3 "2021-05-17T14:07:14Z")

</div>

Hi Doug, thanks for your reply.  
Even though glfwSwapInterval() is set to 1, I keep getting the same behaviour, framerate is as expected (60fps), but cpu usage is still high.  
I also tried the following:  
Checking the WGL\_EXT\_swap\_control extension (is supported).  
Forcing the vSync through nvidia control panel (no changes on cpu usage).

I also noticed that setting glfwSwapInterval() to a higher value works as expected reducing framerate , however the cpu usage is still high.  
I’m already using glfwPollEvents.

 ![CPU2](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/6d3040bd93f280d216976a8bb6b22b356a428c0f.png)

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [May 17, 2021, 3:06pm UTC](https://discourse.glfw.org/t/high-cpu-usage-when-window-is-on-fullscreen/1859/4 "2021-05-17T15:06:14Z")

</div>

Correction to earlier post: I meant you can use `glfwWaitEvents` which waits for input instead of `glfwPollEvents`.

If your framerate is 60fps, then your frame is taking ~16ms. You then need to check how much of that time is spent in your application and how much in the `glfwSwapBuffers` function, the majority of which will likely be spent in the graphics driver, over which you have no control.

The difference between windowed mode and fullscreen CPU usage is potentially down to the Windows implementation of `glfwSwapBuffers` using [DwmFlush when in windowed mode & when desktop composition is enabled](https://github.com/glfw/glfw/blob/114776a24605418e6d719d2f30141e351e93c6e0/src/wgl_context.c#L322-L342). Since [DwmFlush](https://docs.microsoft.com/en-us/windows/win32/api/dwmapi/nf-dwmapi-dwmflush) blocks the thread until the flush is performed the thread is idle during this time. However the fullscreen implementation might spin or do work, depending on the driver implementation.
