Jump to content

[Help] Definition of 'nil'


Mature

Recommended Posts

  • Moderators
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.

 

  • Like 1
  • Thanks 1
Link to comment

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...