Logging System (Question about efficiency)

Hello!
So I have been working on a logging system where it logs chat messages, commands ran and other things.

I realized that I shouldn’t store the chatlogs indefinitely, so I figured I should take care of clearing up the oldest chatlogs from the array. The array looks something like this:

local chat_logs = {
  [1] = {} -- First message
  [2] = {} -- Second message
  [n] = {} -- nth message
}

Essentially, I have to remove the start of the array. However, I cannot simply equal the value to nil, I have to completely remove it from the array using table.remove

So here’s my question: is there going to be any performance issues with using table.remove since it reindexes every item after the 1st one? How fast is it? Should I worry about it if my array has 5000 items in it?

Thanks!

3 Likes

I was curious as well and just set up a little test to see.

I created two tables:

image

table 1 will hold a large amount of messages
table 2 will hold only 1

then I compared how long table.remove took on both

pretty hacky but I just threw it together
image

and the output:

image
Table2’s operation actually took 0.0000002384185791015625

Then I wanted to test if it was different when doing table.find as well (with considerably more indices)

the output:

image

table1 ended up taking 1.252 MS
and table2 ended up taking only 0.000715 MS

so you shouldn’t face and noticeable performance differences.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.