{"action":"opened","issue":{"url":"https://api.github.com/repos/Blu3wolf/Treefarm-Lite/issues/15","repository_url":"https://api.github.com/repos/Blu3wolf/Treefarm-Lite","labels_url":"https://api.github.com/repos/Blu3wolf/Treefarm-Lite/issues/15/labels{/name}","comments_url":"https://api.github.com/repos/Blu3wolf/Treefarm-Lite/issues/15/comments","events_url":"https://api.github.com/repos/Blu3wolf/Treefarm-Lite/issues/15/events","html_url":"https://github.com/Blu3wolf/Treefarm-Lite/issues/15","id":143770856,"number":15,"title":"Treefarm performance with LOTS of treefarms","user":{"login":"Blu3wolf","id":12153041,"avatar_url":"https://avatars.githubusercontent.com/u/12153041?v=3","gravatar_id":"","url":"https://api.github.com/users/Blu3wolf","html_url":"https://github.com/Blu3wolf","followers_url":"https://api.github.com/users/Blu3wolf/followers","following_url":"https://api.github.com/users/Blu3wolf/following{/other_user}","gists_url":"https://api.github.com/users/Blu3wolf/gists{/gist_id}","starred_url":"https://api.github.com/users/Blu3wolf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Blu3wolf/subscriptions","organizations_url":"https://api.github.com/users/Blu3wolf/orgs","repos_url":"https://api.github.com/users/Blu3wolf/repos","events_url":"https://api.github.com/users/Blu3wolf/events{/privacy}","received_events_url":"https://api.github.com/users/Blu3wolf/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-03-27T02:50:49Z","updated_at":"2016-03-27T02:50:49Z","closed_at":null,"body":"Treefarms are maintained by the fieldmaintainer method in control.lua. This updates all treefarms in a queue (global.tf.fieldList). \r\n`global.tf.fieldList[1].nextUpdate = tick + 60\r\n  local field = table.remove(global.tf.fieldList, 1)\r\n  table.insert(global.tf.fieldList, field)`\r\ntable.insert and table.remove for lua tables more than 100 entries can cause performance issues. This suggests that to have 600 treefarms at 60 FPS, the queue currently implemented will not work. \r\n\r\nThe sparse table solution proposed by @Rseding91 for seed planting may also work for the treefarms themselves:\r\n\r\n> Lua tables do not work well when you table.insert into the middle of them or table.remove from not-the-end of them. I can't stress this enough: every time you table.insert() into the middle of an indexed lua table it has to push all elements after the insertion point out by 1. Every time you table.remove() from not-the-end all elements after the one you remove are shifted up by one. This happens every time a tree is grown and so it eats a *ton* of CPU time.\r\n\r\n> To fix this: you can use (like I did) a sparse table of trees to grow. The \"trees to grow\" contains a table of tables. You index the table with the current tick to see if that index contains a table of trees to grow and if it does you grow all of those trees and then re-insert them at the next tick they should grow.\r\n\r\nIn this case, instead of tables of tables of trees to grow at this tick, indexed by tick, it would be tables of tables of treefarms to maintain at this tick, indexed by tick. "}}