{"action":"created","issue":{"url":"https://api.github.com/repos/godotengine/godot/issues/7832","repository_url":"https://api.github.com/repos/godotengine/godot","labels_url":"https://api.github.com/repos/godotengine/godot/issues/7832/labels{/name}","comments_url":"https://api.github.com/repos/godotengine/godot/issues/7832/comments","events_url":"https://api.github.com/repos/godotengine/godot/issues/7832/events","html_url":"https://github.com/godotengine/godot/issues/7832","id":208476616,"number":7832,"title":"Question on multi Threading efficiency","user":{"login":"Maveyyl","id":17054503,"avatar_url":"https://avatars.githubusercontent.com/u/17054503?v=3","gravatar_id":"","url":"https://api.github.com/users/Maveyyl","html_url":"https://github.com/Maveyyl","followers_url":"https://api.github.com/users/Maveyyl/followers","following_url":"https://api.github.com/users/Maveyyl/following{/other_user}","gists_url":"https://api.github.com/users/Maveyyl/gists{/gist_id}","starred_url":"https://api.github.com/users/Maveyyl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Maveyyl/subscriptions","organizations_url":"https://api.github.com/users/Maveyyl/orgs","repos_url":"https://api.github.com/users/Maveyyl/repos","events_url":"https://api.github.com/users/Maveyyl/events{/privacy}","received_events_url":"https://api.github.com/users/Maveyyl/received_events","type":"User","site_admin":false},"labels":[{"id":279097162,"url":"https://api.github.com/repos/godotengine/godot/labels/discussion","name":"discussion","color":"ee77ee","default":false},{"id":279097966,"url":"https://api.github.com/repos/godotengine/godot/labels/topic:core","name":"topic:core","color":"ffdd44","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2017-02-17T15:38:31Z","updated_at":"2017-02-18T10:04:52Z","closed_at":null,"body":"<!--\r\nREADME: Incompatibilities and broken features in the current master branch / 3.0-alpha\r\nare known and expected due to important refactoring work, so no need to report them for now. Thanks!\r\n-->\r\n\r\n**Operating system or device - Godot version:**\r\nProcessor quad core\r\nWindows 7 and 10\r\nGodot 2.1.2 stable\r\nGodot legacy branch compiled 19/01/2017\r\n\r\n**Issue description:**\r\nI try to make a thread pool singleton. It creates a fixed count of Threads, I feed it with tasks and it tries to keep the threads busy as much as possible until every task is done. But I've met negative improvement of the computation time of my tasks.\r\n\r\nI've then made an experiment:\r\nuse a simple function that takes lot of time, a for loop incrementing a variable.\r\n\r\nI run it once, it takes 200ms to execute.\r\nI run it in a thread, it takes 200ms.\r\nI run it 4 times, it takes 800ms to finish. Normal.\r\nI run it in 4 threads, it takes 550 ms. 0.66 times the previous result. Kinda disappointing.\r\n\r\nI check in the profiler:\r\nOn the average, the function needs 200ms when executed single threaded.\r\nOn the average, the function needs 400ms when executed in many separate threads. The more threads, the slower will be the function.\r\n\r\nI use a compiled version of godot that corresponds to the legacy branch of 19/01/2017, I also tried on the version 2.1.2 stable and the results were worse.\r\n\r\nI open this issue to ask if this behaviour seems normal. I've already messed with multithreading in C and Java on quad-cores and cutting 2/3 of the computation time is not an usual result for me.\r\n\r\n\r\n**Steps to reproduce:**\r\n```gdscript\r\nfunc _ready():\r\n\tvar test_count = 4\r\n\tvar arg1 = 500000\r\n\tvar start\r\n\tvar stop\r\n\tvar test_time\r\n\tvar test_multi_time\r\n\r\n\tstart = OS.get_ticks_msec()\r\n\tfor i in range(test_count):\r\n\t\ttest(arg1)\r\n\tstop = OS.get_ticks_msec()\r\n\ttest_time = stop-start\r\n\t\r\n\tvar threads = []\r\n\tthreads.append( Thread.new() )\r\n\tthreads.append( Thread.new() )\r\n\tthreads.append( Thread.new() )\r\n\tthreads.append( Thread.new() )\r\n\tstart = OS.get_ticks_msec()\r\n\tfor i in range(test_count):\r\n\t\tthreads[i].start(self, \"test_multi\", arg1)\r\n\tthreads[0].wait_to_finish()\r\n\tthreads[1].wait_to_finish()\r\n\tthreads[2].wait_to_finish()\r\n\tthreads[3].wait_to_finish()\r\n\tstop = OS.get_ticks_msec()\r\n\ttest_multi_time = stop-start\r\n\r\n\t\r\n\tprint(\"test : \", test_time)\r\n\tprint(\"test multi: \", test_multi_time)\r\n\tprint(\"ratio: \", float(test_multi_time)/test_time)\r\n\t\r\n\r\nfunc test(arg1):\r\n\tvar acc = 0\r\n\tfor i in range(arg1):\r\n\t\tacc +=1\r\n\treturn acc\r\n\r\nfunc test_multi(arg1):\r\n\tvar acc = 0\r\n\tfor i in range(arg1):\r\n\t\tacc +=1\r\n\treturn acc\r\n```\r\n\r\n**Link to minimal example project:**\r\n<!-- Optional but very welcome. You can drag and drop a zip archive to upload it. -->:\r\n"},"comment":{"url":"https://api.github.com/repos/godotengine/godot/issues/comments/280835532","html_url":"https://github.com/godotengine/godot/issues/7832#issuecomment-280835532","issue_url":"https://api.github.com/repos/godotengine/godot/issues/7832","id":280835532,"user":{"login":"razvanc-r","id":1177508,"avatar_url":"https://avatars.githubusercontent.com/u/1177508?v=3","gravatar_id":"","url":"https://api.github.com/users/razvanc-r","html_url":"https://github.com/razvanc-r","followers_url":"https://api.github.com/users/razvanc-r/followers","following_url":"https://api.github.com/users/razvanc-r/following{/other_user}","gists_url":"https://api.github.com/users/razvanc-r/gists{/gist_id}","starred_url":"https://api.github.com/users/razvanc-r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/razvanc-r/subscriptions","organizations_url":"https://api.github.com/users/razvanc-r/orgs","repos_url":"https://api.github.com/users/razvanc-r/repos","events_url":"https://api.github.com/users/razvanc-r/events{/privacy}","received_events_url":"https://api.github.com/users/razvanc-r/received_events","type":"User","site_admin":false},"created_at":"2017-02-18T10:04:52Z","updated_at":"2017-02-18T10:04:52Z","body":"@volzhs what do the numbers represent? Is it the time per function or the total running time of the program? in ms (I assume - if it's time)? if this is correct it means that in all cases the thread test is slower. How many threads did you use for `test_multi`? so many questions... :) you need better presentation :P"}}
{"actor":{"display_login":"razvanc-r"}}