From 77c3e94faada80038992abe07940c4e921ff67ff Mon Sep 17 00:00:00 2001 From: zxx43 Date: Fri, 4 Jun 2021 14:34:01 +0800 Subject: [PATCH] V3.1.2 zxx43 performance 2 (#8764) * reduce clear frequency & check translate or rotate in updateWorldTransform function https://github.com/cocos-creator/3d-tasks/issues/7487 * make clear node as a static function --- cocos/core/director.ts | 1 + cocos/core/scene-graph/node.ts | 34 ++++++++++++++++++++++------------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/cocos/core/director.ts b/cocos/core/director.ts index 6850d56deb..6801178344 100644 --- a/cocos/core/director.ts +++ b/cocos/core/director.ts @@ -907,6 +907,7 @@ export class Director extends EventTarget { eventManager.frameUpdateListeners(); Node.resetHasChangedFlags(); + Node.clearNodeArray(); this._totalFrames++; } } diff --git a/cocos/core/scene-graph/node.ts b/cocos/core/scene-graph/node.ts index 06ed421081..740cdb15db 100644 --- a/cocos/core/scene-graph/node.ts +++ b/cocos/core/scene-graph/node.ts @@ -167,6 +167,13 @@ export class Node extends BaseNode { */ public static TransformBit = TransformBit; + /** + * @en Counter to clear node array + * @zh 清除节点数组计时器 + */ + private static ClearFrame = 0; + private static ClearRound = 1000; + // UI 部分的脏数据 public _uiProps = new NodeUIProperties(this); @@ -610,12 +617,6 @@ export class Node extends BaseNode { } dirtyBit = childDirtyBit; } - if (this._invalidFrame < this._roundTime) { - this._invalidFrame++; - } else { - array_a.length = 0; - this._invalidFrame = 0; - } } /** @@ -707,12 +708,6 @@ export class Node extends BaseNode { child._dirtyFlags = TransformBit.NONE; cur = child; } - if (this._updateFrame < this._roundTime) { - this._updateFrame++; - } else { - array_a.length = 0; - this._updateFrame = 0; - } } // =============================== @@ -1213,6 +1208,21 @@ export class Node extends BaseNode { bookOfChange.clear(); } + /** + * @en + * clear node array + * @zh + * 清除节点数组 + */ + public static clearNodeArray () { + if (Node.ClearFrame < Node.ClearRound) { + Node.ClearFrame++; + } else { + Node.ClearFrame = 0; + array_a.length = 0; + } + } + /** * @en * Synchronize the js transform to the native layer.