{"action":"created","issue":{"url":"https://api.github.com/repos/minetest/minetest/issues/3182","labels_url":"https://api.github.com/repos/minetest/minetest/issues/3182/labels{/name}","comments_url":"https://api.github.com/repos/minetest/minetest/issues/3182/comments","events_url":"https://api.github.com/repos/minetest/minetest/issues/3182/events","html_url":"https://github.com/minetest/minetest/issues/3182","id":106919801,"number":3182,"title":"Mapgen code should be running in its own thread.","user":{"login":"RobertZenz","id":611377,"avatar_url":"https://avatars.githubusercontent.com/u/611377?v=3","gravatar_id":"","url":"https://api.github.com/users/RobertZenz","html_url":"https://github.com/RobertZenz","followers_url":"https://api.github.com/users/RobertZenz/followers","following_url":"https://api.github.com/users/RobertZenz/following{/other_user}","gists_url":"https://api.github.com/users/RobertZenz/gists{/gist_id}","starred_url":"https://api.github.com/users/RobertZenz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RobertZenz/subscriptions","organizations_url":"https://api.github.com/users/RobertZenz/orgs","repos_url":"https://api.github.com/users/RobertZenz/repos","events_url":"https://api.github.com/users/RobertZenz/events{/privacy}","received_events_url":"https://api.github.com/users/RobertZenz/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/minetest/minetest/labels/@%20Mapgen","name":"@ Mapgen","color":"009800"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-09-17T06:28:14Z","updated_at":"2015-10-18T07:33:14Z","closed_at":null,"body":"Currently generating a block takes some time, this time is quite acceptable if we are talking about a default mapgen implemented in C++. But if there is a mapgen written in Lua (does not need to be a complete mapgen, customizations already suffice), registered with `register_on_generated` the time can skyrocket quite fast.\r\n\r\nThis is not a problem in itself, if the mapgen is slow the mapgen is slow, the real problem is that the mapgen is a stop-it-all operation, including updating of non-affected blocks and even player positions. In singleplayer this is mainly an inconvenience, in multiplayer this is a real problem. Somebody goes exploring the world and the server lags for everyone.\r\n\r\nThe mapgen should run in its own thread including the callbacks registered at `register_on_generated` and should block as little as possible of the actual gameplay. I believe that the player is already unable to enter non-loaded/generated blocks without the no-clip option, so there wouldn't really be an issue if the mapgen is too slow and the player too fast. Ideally the mapgen would only prepare the block which is then inserted in one swooping operation into the map itself."},"comment":{"url":"https://api.github.com/repos/minetest/minetest/issues/comments/148986974","html_url":"https://github.com/minetest/minetest/issues/3182#issuecomment-148986974","issue_url":"https://api.github.com/repos/minetest/minetest/issues/3182","id":148986974,"user":{"login":"kwolekr","id":630595,"avatar_url":"https://avatars.githubusercontent.com/u/630595?v=3","gravatar_id":"","url":"https://api.github.com/users/kwolekr","html_url":"https://github.com/kwolekr","followers_url":"https://api.github.com/users/kwolekr/followers","following_url":"https://api.github.com/users/kwolekr/following{/other_user}","gists_url":"https://api.github.com/users/kwolekr/gists{/gist_id}","starred_url":"https://api.github.com/users/kwolekr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kwolekr/subscriptions","organizations_url":"https://api.github.com/users/kwolekr/orgs","repos_url":"https://api.github.com/users/kwolekr/repos","events_url":"https://api.github.com/users/kwolekr/events{/privacy}","received_events_url":"https://api.github.com/users/kwolekr/received_events","type":"User","site_admin":false},"created_at":"2015-10-18T07:33:13Z","updated_at":"2015-10-18T07:33:13Z","body":"The mapgen does run in its own thread.  It just needs to be synchronized with the rest of the map because it's unpredictable which functions might be run in a script, and locking inside of the script itself when needed has been tried and is much slower."}}