Comparing Tables vs GetChildren() indexing

Title is a bit vague; assigning objects to a table value (after getting them) as compared to getting the object from its ancestry (to search) every time it is called

Q: Which of the two is better to conserve server processing power?

I started thinking about this as I hopped into the docs for an unrelated answer. My initial thought process was that getting the instance from a table (after its been assigned to a table value ofc) is much more efficient. But then again, how much processing really is used for built in Get() functions? Is it demanding?

If any of you have a resource on server memory and would like to post it here, it would be appreciated.

Generally speaking, indexing a table is lightyears faster than indexing a Roblox object. If you’re accessing an object multiple times, you really ought to save the reference to a variable or within a table. Avoid calling GetChildren more than necessary, as it has to allocate memory for a new table every single time.

This is, of course, assuming performance matters here. The very beginning of conversations like this tend to waste more time than generally worthwhile. Make it work, then make it work well.

1 Like

Thank you very much.

Are there any guides you use in particular to find which functions take jabs at server performance?

Again, I appreciate it.

I index a table. You can use Benchmark Plugin to test which way is faster.

1 Like

You can use os.clock to profile your code and experiment with various optimizations, but again beware of spending too much time figuring out what is faster by only a few microseconds. It’s often better in programming to accept that something is fast enough for your purposes, and look out only for bigger fish to fry, like memory leaks.

The MicroProfiler is a fantastic tool which can help you measure execution time. It has a bit of a learning curve, though, beware!

1 Like