- Unity Game Optimization
- Dr. Davide Aversa Chris Dickinson
- 299字
- 2021-06-24 12:13:02
Sharing calculation output
Performance can be saved by having multiple objects share the result of some calculation; of course, this only works if all of them generate the same result. Such situations are often easy to spot but can be tricky to refactor, and so exploiting this would be very implementation-dependent.
Some examples might include finding an object in a scene, reading data from a file, parsing data (such as XML or JSON), finding something in a big list or deep dictionary of information, calculating pathing for a group of Artificial Intelligence (AI) objects, complex mathematics-like trajectories, raycasting, and so on.
Think about each time an expensive operation is undertaken, and consider whether it is being called from multiple locations but always results in the same output. If this is the case, then it would be wise to restructure things so that the result is calculated once and then distributed to every object that needs it to minimize the amount of recalculation. The biggest cost is typically just a small loss in code simplicity, although we may inflict some extra overhead by moving the value around.
Note that it's often easy to get into the habit of hiding some big complex function in a base class, and then we define derived classes that make use of that function, completely forgetting how costly that function is because we rarely glance at that code again. It's best to use the Unity Profiler to tell us how many times that expensive function may be called, and as always, don't preoptimize those functions unless it's been proven to be a performance issue. No matter how expensive it may be, if it doesn't cause us to exceed performance restrictions (such as frame rate and memory consumption), then it's not really a performance problem.
- LabVIEW2018中文版 虛擬儀器程序設計自學手冊
- Java面向對象軟件開發
- Linux C/C++服務器開發實踐
- Learning ArcGIS Pro 2
- Learning ASP.NET Core 2.0
- Java加密與解密的藝術
- 假如C語言是我發明的:講給孩子聽的大師編程課
- MATLAB定量決策五大類問題
- Troubleshooting PostgreSQL
- PhoneGap Mobile Application Development Cookbook
- SQL經典實例(第2版)
- 低代碼平臺開發實踐:基于React
- C#開發案例精粹
- SSM開發實戰教程(Spring+Spring MVC+MyBatis)
- Python機器學習:預測分析核心算法