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
This commit is contained in:
zxx43
2021-06-04 14:34:01 +08:00
committed by GitHub
parent 8570e27bc3
commit 77c3e94faa
2 changed files with 23 additions and 12 deletions
+1
View File
@@ -907,6 +907,7 @@ export class Director extends EventTarget {
eventManager.frameUpdateListeners();
Node.resetHasChangedFlags();
Node.clearNodeArray();
this._totalFrames++;
}
}
+22 -12
View File
@@ -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.