View Single Post
01-05-06, 03:19 PM   #5
Cyrael
A Murloc Raider
Join Date: Jan 2006
Posts: 7
Reducing global namespace clutter will (very slightly) increase memory for the extra table overhead, and will improve performance. This is a fundamental truth of indexing into any table in any programming language, and Lua tables are no different. Your first test contains flawed data:

Variables 1638401-3276800: 3295217 globals, 0 tables, 163834 mem added, 0.100 mem/var, 0.019 sec 100k local calls, 0.021 sec globals, 0.025 sec tables
...
Variables 1638401-3276800: 18602 globals, 1 tables, 163833 mem added, 0.100 mem/var, 0.023 sec 100k local calls, 0.022 sec globals, 0.026 sec tables
You cannot use less memory between a global reference and a tabled reference. Your table should be at least 13 bytes bigger than using the global namespace alone. This test appears to be flawed, I'll look further into it when I have time.

In the latter tests, it appears that only the number of GETTABLE calls actually take place. I can assure you that a single GETTABLE call into a 3,000,000 element table will take more time than one GETTABLE call into a 250 element table, and another into a 100 element table.

The object oriented approach provides a facility to avoid searching through data that is determined to be unnecessary. In both cases, your benchmarks either test the wrong information or are flawed, and so your benchmarking tests are ultimately incorrect. I've seen other benchmarks that test the issue accurately, and they show a notable performance improvement across the board when reducing the global namespace clutter. I'll try to find the benchmark code for you to see the difference.

Last edited by Cyrael : 01-05-06 at 03:37 PM.
  Reply With Quote