{"action":"created","issue":{"url":"https://api.github.com/repos/go-gl/glfw/issues/223","repository_url":"https://api.github.com/repos/go-gl/glfw","labels_url":"https://api.github.com/repos/go-gl/glfw/issues/223/labels{/name}","comments_url":"https://api.github.com/repos/go-gl/glfw/issues/223/comments","events_url":"https://api.github.com/repos/go-gl/glfw/issues/223/events","html_url":"https://github.com/go-gl/glfw/issues/223","id":356192575,"node_id":"MDU6SXNzdWUzNTYxOTI1NzU=","number":223,"title":"glfw.PollEvents is slow when any key is pressed on Mac","user":{"login":"ysmolsky","id":140245,"node_id":"MDQ6VXNlcjE0MDI0NQ==","avatar_url":"https://avatars2.githubusercontent.com/u/140245?v=4","gravatar_id":"","url":"https://api.github.com/users/ysmolsky","html_url":"https://github.com/ysmolsky","followers_url":"https://api.github.com/users/ysmolsky/followers","following_url":"https://api.github.com/users/ysmolsky/following{/other_user}","gists_url":"https://api.github.com/users/ysmolsky/gists{/gist_id}","starred_url":"https://api.github.com/users/ysmolsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ysmolsky/subscriptions","organizations_url":"https://api.github.com/users/ysmolsky/orgs","repos_url":"https://api.github.com/users/ysmolsky/repos","events_url":"https://api.github.com/users/ysmolsky/events{/privacy}","received_events_url":"https://api.github.com/users/ysmolsky/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-09-01T10:42:19Z","updated_at":"2018-09-01T13:33:24Z","closed_at":null,"author_association":"NONE","body":"Calling glfw.PollEvents() takes 3-5 ms at peaks even without any callbacks installed on Mac.\r\n\r\nI have discovered this problem when working with Pixel which uses glfw for the input. I have \"benchmarked\" wrapper [function](https://github.com/faiface/pixel/blob/master/pixelgl/input.go#L375) this way:\r\n\r\n```\r\n\tmainthread.Call(func() {\r\n\t\tst := time.Now()\r\n\t\tglfw.PollEvents()\r\n\t\tfmt.Printf(\"%8.6f\\n\", time.Since(st).Seconds())\r\n\t})\r\n```\r\nWhen key is not pressed I see that it takes ~ 0.1 millisecond. But when I press any key then there are spikes up to 4-6 milliseconds. See the output from the debug hack:\r\n```\r\n0.004469\r\n0.004031\r\n0.000045\r\n0.000087\r\n0.003548\r\n0.003326\r\n0.000043\r\n0.003076\r\n0.000166\r\n0.003151\r\n0.000122\r\n0.003320\r\n\r\n```\r\nAlso I can reproduce it with this example: https://github.com/go-gl/example/tree/master/gl21-cube\r\n\r\nI am not sure where to go with this. But this is a major show stopper for making games in Go. 4ms out total 16ms per frame is just too big price for one function.\r\n\r\nHow can I investigate it further?"},"comment":{"url":"https://api.github.com/repos/go-gl/glfw/issues/comments/417860088","html_url":"https://github.com/go-gl/glfw/issues/223#issuecomment-417860088","issue_url":"https://api.github.com/repos/go-gl/glfw/issues/223","id":417860088,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNzg2MDA4OA==","user":{"login":"ysmolsky","id":140245,"node_id":"MDQ6VXNlcjE0MDI0NQ==","avatar_url":"https://avatars2.githubusercontent.com/u/140245?v=4","gravatar_id":"","url":"https://api.github.com/users/ysmolsky","html_url":"https://github.com/ysmolsky","followers_url":"https://api.github.com/users/ysmolsky/followers","following_url":"https://api.github.com/users/ysmolsky/following{/other_user}","gists_url":"https://api.github.com/users/ysmolsky/gists{/gist_id}","starred_url":"https://api.github.com/users/ysmolsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ysmolsky/subscriptions","organizations_url":"https://api.github.com/users/ysmolsky/orgs","repos_url":"https://api.github.com/users/ysmolsky/repos","events_url":"https://api.github.com/users/ysmolsky/events{/privacy}","received_events_url":"https://api.github.com/users/ysmolsky/received_events","type":"User","site_admin":false},"created_at":"2018-09-01T13:33:24Z","updated_at":"2018-09-01T13:33:24Z","author_association":"NONE","body":"I was able to reproduce this with glfw 3.2.1 and C using those code:\r\n```c\r\n  /* Loop until the user closes the window */\r\n  while (!glfwWindowShouldClose(window))\r\n  {\r\n    /* Render here */\r\n    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the buffers\r\n\r\n    /* Swap front and back buffers */\r\n    glfwSwapBuffers(window);\r\n\r\n    /* Poll for and process events */\r\n    double seconds = glfwGetTime();\r\n    glfwPollEvents();\r\n    seconds = glfwGetTime() - seconds;\r\n    printf(\"%.7f\\n\", seconds);\r\n\r\n  }\r\n```\r\nI get this when I hold any key pressed:\r\n```\r\n0.0030390\r\n0.0013822\r\n0.0031350\r\n0.0000474\r\n0.0034653\r\n0.0000789\r\n0.0036935\r\n0.0000486\r\n0.0041693\r\n0.0000461\r\n0.0031637\r\n0.0000409\r\n0.0034748\r\n```"}}
{"actor":{"display_login":"ysmolsky"}}