glfw: glfwPollEvents is slow on El Capitan, glfw 3.2.1
glfwPollEvents takes more than 3 milliseconds when I hold any keys pressed, otherwise it takes less than 0.1 millisecond.
I am able to reproduce this with glfw 3.2.1 and C using the code:
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the buffers
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
double seconds = glfwGetTime();
glfwPollEvents();
seconds = glfwGetTime() - seconds;
printf("%.7f\n", seconds);
}
I get this when I hold any key pressed:
0.0030390
0.0013822
0.0031350
0.0000474
0.0034653
0.0000789
0.0036935
0.0000486
0.0041693
0.0000461
0.0031637
0.0000409
0.0034748
The original ticket was created for the Go wrapper, but it turned out that it’s a problem with glfw, not the wrapper: https://github.com/go-gl/glfw/issues/223
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 17 (5 by maintainers)
Commits related to this issue
- fix stuttering bug, lock to 60 fps via vsync 1. For some reason glfwPollEvents takes more then 3 milliseconds when any key is pressed on Mac. I cannot fix this, but I filed an issue https://github.co... — committed to ysmolski/unnamed-archery-game by ysmolski 6 years ago
- fix stuttering bug, lock to 60 fps via vsync 1. For some reason glfwPollEvents takes more then 3 milliseconds when any key is pressed on Mac. I cannot fix this, but I filed an issue https://github.co... — committed to ysmolski/unnamed-archery-game by ysmolski 6 years ago
I did as you suggested. Program:
Output
Thanks for the detailed report.
Aside:
printf("%s\n", glfwGetVersionString());is a little bit more useful thanprintf("%d %d\n", GLFW_VERSION_MAJOR, GLFW_VERSION_MINOR);because it contains more information.For reference, running the same test on my Linux PC takes 11ms for the very first call, but subsequent calls to glfwPollEvents reliably take around 0.07ms (around 6x faster than your results).