# Drastic performance decrease when full screen vs almost full screen

**URL:** <https://discourse.glfw.org/t/drastic-performance-decrease-when-full-screen-vs-almost-full-screen/2631>\
**Category:** support\
**Created:** [May 14, 2024, 2:30am UTC](https://discourse.glfw.org/t/drastic-performance-decrease-when-full-screen-vs-almost-full-screen/2631 "2024-05-14T02:30:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bill.connelly](https://avatars.discourse-cdn.com/v4/letter/b/c89c15/32.png) [@bill.connelly](https://discourse.glfw.org/u/bill.connelly)\
**Post date:** [May 14, 2024, 2:30am UTC](https://discourse.glfw.org/t/drastic-performance-decrease-when-full-screen-vs-almost-full-screen/2631/1 "2024-05-14T02:30:05Z")

</div>

GLFW 3.3.8-1  
Raspberry Pi 5.  
Raspberry Pi OS: Linux raspberrypi 6.6.28+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.6.28-1+rpt1 (2024-04-22) aarch64 GNU/Linux  
Windowing: Wayland

My monitors native resolution is 1920 x 1200. If I make a window that is _just_ not full screen (1920, 1180) and then repeatedly call glfwSwapBuffers() with no kind of rendering and time how long between buffer swaps, I get about 0.2 milliseconds, i.e. 5000 FPS

However, if I make the window full screen, and perform the same test I get a handful of frames with a 0.2 inter-frame time. Then it drops to 33.3 millisecond (which is very curiously, almost exactly 2 refreshes), i.e. 30 FPS

I appreciate I am on some atypical hardware, so I’m happy to try to look into anything.

My test code is as follows:

```c
#include <stdio.h>
#include <GLFW/glfw3.h>
#include <sys/time.h>

struct timeval tv;
unsigned long
  frameCount = 0,
  time_in_micros,
  oldTime;

int main(void) {

    glfwInit();

    GLFWmonitor* primaryMonitor = glfwGetPrimaryMonitor();
    const GLFWvidmode* mode = glfwGetVideoMode(primaryMonitor);
 
    //glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate); //This makes no difference
    
    //Swapping between these two versions are what causes problems.
    //GLFWwindow* window = glfwCreateWindow(1920, 1180, "My Title", NULL, NULL);
    GLFWwindow* window = glfwCreateWindow(1920, 1200, "My Title", primaryMonitor, NULL);

    glfwMakeContextCurrent(window);
    glfwSwapInterval(0);

    while (!glfwWindowShouldClose(window)) {
        frameCount++;
        glfwSwapBuffers(window);
        if (frameCount % 10 == 0) {
            oldTime = time_in_micros;
            gettimeofday(&tv,NULL);
            time_in_micros = 1000000 * tv.tv_sec + tv.tv_usec;
            printf("Interframe time is %f\n", (float)(time_in_micros-oldTime)/10000);
        }
    }

    glfwTerminate();
    return 0;
}

```

---

<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 14, 2024, 10:30am UTC](https://discourse.glfw.org/t/drastic-performance-decrease-when-full-screen-vs-almost-full-screen/2631/2 "2024-05-14T10:30:48Z")

</div>

I’m not sure what’s causing this. I note you’re not polling events though, which I would recommend doing (i.e. call `glfwPollEvents()` after `glfwSwapBuffers(window)`).

GLFW itself isn’t doing anything special here, as the abstraction of `glfwSwapBuffers` is [pretty thin in your case](https://github.com/glfw/glfw/blob/b35641f4a3c62aa86a0b3c983d163bc0fe36026d/src/egl_context.c#L275-L294) (pretty much just calling `eglSwapBuffers`), so the behaviour is almost certainly down to the OS + window manager + OpenGL + driver behaviour. There could be something which GLFW is doing to cause this, but it seems unlikely.

The first few long frames could be due to the switch from windowed mode to fullscreen, then the rest due to vsync being forced on when fullscreen, perhaps even forced to 2.

Note: for timing you can use the GLFW timer functions: [GLFW: Time input](https://www.glfw.org/docs/3.0/group__time.html)

---

<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 15, 2024, 10:32am UTC](https://discourse.glfw.org/t/drastic-performance-decrease-when-full-screen-vs-almost-full-screen/2631/3 "2024-05-15T10:32:17Z")

</div>

You might want to try using X11 instead of Wayland to see if that makes a difference. I know that there are outstanding problems with [Wayland and glSwapBuffers](https://github.com/libsdl-org/SDL/pull/9345) (at the Wayland level, rather than GLFW - the linked issue is with SDL).

---

<div class="post-metadata">

**Author:** ![bill.connelly](https://avatars.discourse-cdn.com/v4/letter/b/c89c15/32.png) [@bill.connelly](https://discourse.glfw.org/u/bill.connelly)\
**Post date:** [May 16, 2024, 4:44am UTC](https://discourse.glfw.org/t/drastic-performance-decrease-when-full-screen-vs-almost-full-screen/2631/4 "2024-05-16T04:44:11Z")

</div>

Thanks Doug. I believe you that it might not be glfw’s fault. But I wanted to check.

Polling doesn’t change anything. I had that before, but I was just trying to provide you with minimal possible code.

For what it is worth, when I use X11 the code works, but the frame rates jump around a lot. Sometimes 60, sometimes 30 FPS

---

<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 16, 2024, 8:03pm UTC](https://discourse.glfw.org/t/drastic-performance-decrease-when-full-screen-vs-almost-full-screen/2631/5 "2024-05-16T20:03:44Z")

</div>

I am a bit a bit puzzled, but I don’t know what to expect from this system + setup. Do you have any other fullscreen OpenGL non-GLFW apps you can test with?

It might also be worth checking that you’re setting the same mode (bits as well as refresh rate):

```auto
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
 
glfwWindowHint(GLFW_RED_BITS, mode->redBits);
glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits);
glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits);
glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate);
 
GLFWwindow* window = glfwCreateWindow(mode->width, mode->height, "My Title", monitor, NULL);

```

---

<div class="post-metadata">

**Author:** ![bill.connelly](https://avatars.discourse-cdn.com/v4/letter/b/c89c15/32.png) [@bill.connelly](https://discourse.glfw.org/u/bill.connelly)\
**Post date:** [June 13, 2024, 3:20am UTC](https://discourse.glfw.org/t/drastic-performance-decrease-when-full-screen-vs-almost-full-screen/2631/6 "2024-06-13T03:20:24Z")

</div>

This system is absolutely capable for performing 60FPS. For references sake it can run doom 3 at 30FPS. Not exactly killer performance, but more than capable of doing a 60FPS blank window. Indeed, because I couldn’t get this to work, I’ve gone a much more complicated EGL approach. I’d really love to use GLFW. I’m about to raise this as a bug on the raspberry pi github, but I doubt we’ll see much headway.

---

<div class="post-metadata">

**Author:** ![bill.connelly](https://avatars.discourse-cdn.com/v4/letter/b/c89c15/32.png) [@bill.connelly](https://discourse.glfw.org/u/bill.connelly)\
**Post date:** [June 13, 2024, 3:34am UTC](https://discourse.glfw.org/t/drastic-performance-decrease-when-full-screen-vs-almost-full-screen/2631/7 "2024-06-13T03:34:57Z")

</div>

The other thing I don’t understand, is when I call glfwSwapInterval(1); instead of getting 60 FPS, I get 30FPS. Any idea what that might mean?

---

<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:** [June 13, 2024, 12:12pm UTC](https://discourse.glfw.org/t/drastic-performance-decrease-when-full-screen-vs-almost-full-screen/2631/8 "2024-06-13T12:12:02Z")

</div>

> [@bill.connelly](#):
>
> because I couldn’t get this to work, I’ve gone a much more complicated EGL approach. I’d really love to use GLFW.

It would be interesting to see the difference between the EGL approach and the GLFW one in terms of how the swapbuffers works. At the moment it’s tricky to know if this is GLFW specific or not.

> The other thing I don’t understand, is when I call glfwSwapInterval(1); instead of getting 60 FPS, I get 30FPS. Any idea what that might mean?

Usually this is either because the monitor refresh rate is 30Hz or because the frame render takes longer than 16ms. Do you know what refresh rate is set when you are fullscreen (you can get this from `glfwGetVideoMode`)?

As noted above there are known issues with Wayland and glSwapBuffers (which will also affect X11 on Wayland).

There could also be an issue with GLFW on your system but the GLFW code for buffer swapping on EGL is trivial so I can’t see why there would be any impact of using GLFW vs EGL directly:

> <https://github.com/glfw/glfw/blob/master/src/egl_context.c#L275-L299>

EDIT: did you try setting the mode hints as per [Drastic performance decrease when full screen vs almost full screen - #5 by dougbinks](https://discourse.glfw.org/t/drastic-performance-decrease-when-full-screen-vs-almost-full-screen/2631/5)?
