How Should You Prioritize Sustained High-Frequency Calls vs. Call Spikes in Lua Performance Profiling?
In a 50v50 multiplayer combat test, how should you prioritize sustained high frequency Lua calls versus sudden call spikes when FPS remains low?
Prioritize investigations based on actual CPU time and the impact on FPS, rather than call counts alone. When FPS remains consistently low, focus first on call paths that consume significant CPU time over an extended period. For occasional stuttering, investigate sudden call spikes in the frames where the stutters occur. Function call analysis typically reveals two patterns: https://uwa overseas public.oss us east 1.aliyuncs.com/uploads/markdown/e2841297 f51a 4f3c b181 ba4fe5203d19.png \ Sustained high frequency calls: A Lua call path increases from more than 100 calls per frame to over 300 calls per frame, with a relatively high proportion of execution time spent in related nodes. Check whether unnecessary repeated updates are occurring. https://uwa overseas public.oss us east 1.aliyuncs.com/uploads/markdown/fa54c6e2 e354 4bb7 a847 cbd524572d83.png \ Sudden call spikes: Another Lua call path reaches approximately 24,000 calls in individual frames. Check the actual execution time of those frames to determine whether the spikes are causing stuttering. The following two areas should be investigated: 1\. Check function execution time and call frequency Trace the call stack to identify the main CPU intensive nodes, then use call counts to determine whether the overhead comes from repeated execution or high execution time per call. For example, for squad pathfinding and path updates, check whether these operations need to run every frame or could instead be updated on demand. For sudden call spikes, examine the specific operations involved to determine whether such concentrated calls are necessary. 2\. Check cross layer Lua calls If high frequency calls involve interactions between Lua and C or Unity APIs, investigate the overhead caused by repeated calls and evaluate whether some calls can be combined or parts of the logic can be handled in a centralized manner. After optimization, compare Lua function execution time, call counts, and FPS under the same test conditions. Verify whether sustained CPU overhead has decreased and whether significant single frame stutters still occur. Note that Development builds and extensive Lua function instrumentation may introduce additional overhead. To validate optimization results, perform comparisons under the same profiling conditions.