Mature Posted February 16, 2020 Share Posted February 16, 2020 Does setting a variable or memory to 'nil' help server performance or not? If you can give tips on things that help in running the script to get better performance, I would be grateful, thanks. =D Link to comment
Moderators IIYAMA Posted February 16, 2020 Moderators Share Posted February 16, 2020 48 minutes ago, Hazardinho said: Does setting a variable or memory to 'nil' help server performance or not? If you can give tips on things that help in running the script to get better performance, I would be grateful, thanks. =D In most cases not. It does indeed reduce memory, but that only matters when the variable contains a lot of data. For example: A variable that contains a table reference with > 1000 items. Cleaning this data will not boost your performance directly, it will only allow your users to use less HDD memory when they do not have enough ram installed. Which will indirect result in improving the performance. People with 4 gb ram installed on a windows 10 computer, that is segment you are helping. 1 1 Link to comment
ReZurrecti0n Posted February 17, 2020 Share Posted February 17, 2020 I believe it is good practice to nil any variable that is no longer in use, just like using local variables where ever possible. Every penny counts and although one penny alone is nothing, eventually it builds up to greater amounts. But yes, as far as affecting performance, it's exactly as IIYAMA said here 1 Link to comment
Addlibs Posted February 17, 2020 Share Posted February 17, 2020 Regarding specifically Lua-tables, they generally don't shrink as you nil values inside them (but nil'ing the reference to the table itself will clean up the memory at some point when GC runs, same for whatever is being referenced in the table, will be cleaned up, just that the space for its reference in the table will not be cleaned up), as table rehashing only occurs when adding new elements. A messy workaround is to add a lot of nil entries (about twice as much as the table had data at last rehash) to trigger a new rehash, which will shrink the table and remove the original and newly added nil elements. But the process of adding those nils will most likely cost you more in performance than you save up in memory space. You can still opt to nil out any table values regularly as good practice, just know that it probably won't reduce the table size in memory unless you are adding and nil'ing entries regularly. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now