TFS 1.X+ A big table can lag the server?

pepsiman

---
Joined
Nov 17, 2017
Messages
123
Best answers
5
Reaction score
66
Hi, i have a table with a lot of data (strings and integers). I declare it once, but, that may cause lag or something due to memory required to it?
This is the data which contains
 

Delusion

Divine Intellect
Support Team
Joined
Feb 14, 2015
Messages
5,340
Best answers
528
Reaction score
3,069
holy sweet macaroons that's a big table
more than likely it won't lag, it's just going to be a small chunk of memory taken up
 
OP
pepsiman

pepsiman

---
Joined
Nov 17, 2017
Messages
123
Best answers
5
Reaction score
66
@Gesior.pl Sorry for tag you. Is there a way to calculate the memory taken by a table?
 

Gesior.pl

Mega Noob&LOL 2012
Joined
Sep 18, 2007
Messages
2,033
Best answers
19
Reaction score
1,089
Location
PLand
@pepsiman
For LUA I would calculate like this:
- each number [big, small, decimal, floating] - 8 bytes [64bit architecture]
- each string - number of letters + 8 bytes [to store length]
- each table - 8 bytes [to store number of child elements]
- 'objects' are just tables with some key-value pairs
If you define table in LUA script, you can check script size. It will be close to memory usage.

Storing table with size 1GB won't lag server. It can only lag, if there is milion keys in one big table and you iterate over it with 'for'/'while'.
If there is 100 keys, each with 10MB value, it won't lag when you use 'for'/'while'.

When you read table by known key (number/string) execution time should be same:
PHP:
local 1gbTable = {/*... a lot of data ...*/}
local knownKeyText = 'asd'
local dataAsd = 1gbTable[knownKeyText]
local knownKeyNumber = 123
local data123 = 1gbTable[knownKeyNumber]
No matter how big table it is or how many keys it has.

EDIT:
If you want to optimize memory usage or CPU consumption of some LUA script. There is a short documentation (25 pages) with examples of slow code and optimized version:
https://www.lua.org/gems/sample.pdf
 
Last edited:

Delusion

Divine Intellect
Support Team
Joined
Feb 14, 2015
Messages
5,340
Best answers
528
Reaction score
3,069
or you can use this:
the empty table/loop is not necessary, just an example i used to calculate a table with 1000000 values
Lua:
local kb = collectgarbage("count")
local t = {}
for i = 1, 1000000 do
    t[i] = i
end
print(string.format("Estimated memory allocated for table: %.2f MB.", (collectgarbage("count") - kb) / 1024))
my result: Estimated memory allocated for table: 8.00 MB.
 
Top