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

Share 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 would 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 in order to minimize the amount of recalculation. The biggest cost is typically just a small loss in code simplicity, although some extra overhead may be inflicted by passing 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.

主站蜘蛛池模板: 体育| 讷河市| 金堂县| 克拉玛依市| 喀喇| 濮阳市| 茌平县| 滦南县| 叶城县| 雷州市| 盖州市| 晋中市| 类乌齐县| 屯昌县| 桦南县| 南开区| 平湖市| 浮山县| 白水县| 金秀| 沾化县| 襄樊市| 盐边县| 德庆县| 万载县| 曲靖市| 鄯善县| 晋中市| 阿勒泰市| 吐鲁番市| 玉龙| 海口市| 灌云县| 镇江市| 汉阴县| 安国市| 澄城县| 芦山县| 连云港市| 运城市| 长治市|