Hi everyone. Recently I've taken on the task to optimize the FAF base game repository. Since LOUD shows it is possible - why shouldn't we do that too.
As it stands I've made a profiler to help figure out what functions are called often and how to write code that is more efficient. One approach to this is through benchmarks. See also this folder:
All benchmarks (with a similar name) perform the same operations, some faster than others. To give a few examples:
- table-insert.lua / AddInsertGlobal = 0.046 seconds
- table-insert.lua / AddCountAlt= 0.00219 seconds (the regular approach is 500% - 2000% slower (!))
- table-hash.lua / Hash01 = 0.00488
- table-hash.lua / HashCached01 = 0.00341 (the regular approach is about 10% - 30% slower)
- table-loops.lua / ForGetn = 0.2136
- table-loops.lua / ForPairs = 0.3704 (the regular approach is about 40% - 50% slower)
rewriting of existing functions
- table-hash.lua / HashCross1 = 0.08498
- table-hash.lua / HashCrossCached1 = 0.05175 (the regular approach is 30% - 40% slower)
This shows that it is possible from a theoretical perspective. I've been doing work on optimizing projectiles that you can find here:
When 400 Zthuee are firing at one location it takes 12 - 15 ms on the base branch, assuming you are completely zoomed out. On the optimized branch it takes 8 - 9 ms. That is a significant difference on its own - and this is just on projectiles. @CheeseBerry can confirm this - on his computer it runs about 18 - 20 ms on the base branch, where as it runs 14 - 15 ms on the optimized branch.
Up to this point I've only optimized while trying to keep the original logic alive. However, there are some things that I feel are not required for the overall game, are expensive, and can not be made cheaper. I'll use this topic to discuss these issues to get a bearing as to whether people think it is worth changing or taking out of the game.
In order to facilitate discussion each problem will have its own topic on the forum. Please remain on topic, whatever you are writing for. As it is easier for me to identify how people feel about certain changes.