官术网_书友最值得收藏!

  • Unity Game Optimization
  • Dr. Davide Aversa Chris Dickinson
  • 495字
  • 2021-06-24 12:12:59

Best approaches to performance analysis

Good coding practices and project asset management often make finding the root cause of a performance issue relatively simple, at which point the only real problem is figuring out how to improve the code. For instance, if the method only processes a single gigantic for loop, then it will be a pretty safe assumption that the problem is either with how many iterations the loop is performing, whether or not the loop is causing cache misses by reading memory in a non-sequential fashion, how much work is done in each iteration, or how much work it takes to prepare for the next iteration.

Of course, whether we're working individually or in a group setting, a lot of our code is not always written in the cleanest way possible, and we should expect to have to profile some poor coding work from time to time. Sometimes, we are forced to implement a hacky solution for the sake of speed, and we don't always have the time to go back and refactor everything to keep up with our best coding practices. In fact, many code changes made in the name of performance optimization tend to appear very strange or arcane, often making our code base more difficult to read. The common goal of software development is to make code that is clean, feature-rich, and fast. Achieving one of these is relatively easy, but the reality is that achieving two will cost significantly more time and effort, while achieving all three is a near-impossibility.

At its most basic level, performance optimization is just another form of problem solving, and when we overlook the obvious while problem solving, it can be an expensive mistake. Our goal is to use benchmarking to observe our application looking for instances of problematic behavior, and to then use instrumentation to hunt through the code for clues about where the problem originates. Unfortunately, it's often very easy to get distracted by invalid data or jump to conclusions because we're being too impatient or have overlooked a subtle detail. Many of us have run into occasions during software debugging where we could have found the root cause of the problem much faster if we had simply challenged and verified our earlier assumptions. Hunting down performance issues is no different.

A checklist of tasks would be helpful to keep us focused on the issue, and ensure we don't waste time by trying to implement any possible optimization that has no effect on the main performance bottleneck. Of course, every project is different, with its own unique challenges to overcome, but the following checklist is general enough that it should be able to apply to any Unity project:

  • Verify that the target script is present in the scene
  • Verify that the script appears in the scene the correct number of times
  • Verify the correct order of events
  • Minimize ongoing code changes
  • Minimize internal distractions
  • Minimize external distractions
主站蜘蛛池模板: 文化| 静安区| 道孚县| 香港| 江华| 成安县| 马公市| 彝良县| 海晏县| 兴安县| 呼和浩特市| 孟连| 博兴县| 肃南| 长汀县| 聂拉木县| 太康县| 大兴区| 莆田市| 宁城县| 镇安县| 河津市| 泗洪县| 龙海市| 雅安市| 若尔盖县| 定西市| 莫力| 商南县| 西昌市| 旬阳县| 阳江市| 伊川县| 唐海县| 且末县| 获嘉县| 宁波市| 高陵县| 衢州市| 肃宁县| 元谋县|