glfwJoystickPresent takes too much time

Started by bardackx, August 14, 2015, 14:40:32

Previous topic - Next topic

bardackx

In order to support controller hot-plugging I was cheking for present joysticks once per frame (now I do it once every second) and I realized that my frames per second droped from 4 digit numbers to a few 30 to 40.

I traked the isue to the glfwJoystickPresent call and benchmarked-it; now even with the every second fix y have small hickups every (...) second.

Fun fact, after I plug the first controller the cost almost disapears, I am using Windows 10, Inpiron 15 5000 series and a XBOXONE controller.

Is this a normal expected behaviour?

GLFW_JOYSTICK_1 : 19.112301
GLFW_JOYSTICK_2 : 0.038061
GLFW_JOYSTICK_3 : 0.024804
GLFW_JOYSTICK_4 : 0.025659
GLFW_JOYSTICK_5 : 0.021382
GLFW_JOYSTICK_6 : 0.019672
GLFW_JOYSTICK_7 : 0.020527
GLFW_JOYSTICK_8 : 0.019672
GLFW_JOYSTICK_9 : 0.022238
GLFW_JOYSTICK_10 : 0.022666
GLFW_JOYSTICK_11 : 0.023521
GLFW_JOYSTICK_12 : 0.022665
GLFW_JOYSTICK_13 : 0.020956
GLFW_JOYSTICK_14 : 0.021383
GLFW_JOYSTICK_15 : 0.021811
GLFW_JOYSTICK_16 : 0.024376

GLFW_JOYSTICK_1 : 0.004705
GLFW_JOYSTICK_2 : 0.063721
GLFW_JOYSTICK_3 : 0.026942
GLFW_JOYSTICK_4 : 0.024377
GLFW_JOYSTICK_5 : 0.023093
GLFW_JOYSTICK_6 : 0.021383
GLFW_JOYSTICK_7 : 0.014968
GLFW_JOYSTICK_8 : 0.01454
GLFW_JOYSTICK_9 : 0.013685
GLFW_JOYSTICK_10 : 0.01454
GLFW_JOYSTICK_11 : 0.014112
GLFW_JOYSTICK_12 : 0.01454
GLFW_JOYSTICK_13 : 0.014112
GLFW_JOYSTICK_14 : 0.013685
GLFW_JOYSTICK_15 : 0.013685
GLFW_JOYSTICK_16 : 0.014112
EL JOYSTICK_0 (Microsoft PC-joystick driver) SE HA CONECTADO

spasi

Not sure. I tested this:

for ( int i = 0; i < GLFW_JOYSTICK_LAST; i++ ) {
	glfwJoystickPresent(i);
}

it takes ~100μs on my machine (Windows 10). glfwJoystickPresent is calling this function on Windows (checks if it returns JOYERR_NOERROR).

bardackx

It must be my machine then, my code is roughly the same as yours; I'll take my precautions

for (int i = 0; i < joysticks.length; i++)
    joysticks[i].present = glfwJoystickPresent(i) == GL_TRUE;