From be87ddbc5b777fe5670790dd1fd02b84b9040b06 Mon Sep 17 00:00:00 2001 From: Benjamin <45743294+Hoodgail@users.noreply.github.com> Date: Sun, 27 Nov 2022 12:26:00 -0500 Subject: [PATCH 1/4] Use Object.keys rather than JSON.stringify Prevents High CPU usage for big userData's on .toJSON --- src/core/Object3D.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/Object3D.js b/src/core/Object3D.js index 0bf6bb6a2fd868..bba2ce2286851b 100644 --- a/src/core/Object3D.js +++ b/src/core/Object3D.js @@ -687,7 +687,7 @@ class Object3D extends EventDispatcher { if ( this.visible === false ) object.visible = false; if ( this.frustumCulled === false ) object.frustumCulled = false; if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder; - if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData; + if ( Object.keys( this.userData ).length !== 0 ) object.userData = this.userData; object.layers = this.layers.mask; object.matrix = this.matrix.toArray(); From a720da88bc78f5d60d9bbc08e3220c721a91510b Mon Sep 17 00:00:00 2001 From: Benjamin <45743294+Hoodgail@users.noreply.github.com> Date: Sun, 27 Nov 2022 16:17:31 -0500 Subject: [PATCH 2/4] Use for loop instead of Object.keys Object.keys creates a whole new array of every keys, this might be an issue for some people if their data has a lot of keys --- src/core/Object3D.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/Object3D.js b/src/core/Object3D.js index bba2ce2286851b..71e3bb069d4780 100644 --- a/src/core/Object3D.js +++ b/src/core/Object3D.js @@ -687,7 +687,7 @@ class Object3D extends EventDispatcher { if ( this.visible === false ) object.visible = false; if ( this.frustumCulled === false ) object.frustumCulled = false; if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder; - if ( Object.keys( this.userData ).length !== 0 ) object.userData = this.userData; + for ( const key in this.userData ) { object.userData = this.userData; break; }; object.layers = this.layers.mask; object.matrix = this.matrix.toArray(); From 6b84014566d5aa5da4bed32f64c2a3e0bb2e0e46 Mon Sep 17 00:00:00 2001 From: Benjamin <45743294+Hoodgail@users.noreply.github.com> Date: Sun, 27 Nov 2022 16:26:00 -0500 Subject: [PATCH 3/4] linting fix --- src/core/Object3D.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/Object3D.js b/src/core/Object3D.js index 71e3bb069d4780..a7563ec4633c42 100644 --- a/src/core/Object3D.js +++ b/src/core/Object3D.js @@ -687,7 +687,9 @@ class Object3D extends EventDispatcher { if ( this.visible === false ) object.visible = false; if ( this.frustumCulled === false ) object.frustumCulled = false; if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder; - for ( const key in this.userData ) { object.userData = this.userData; break; }; + + // eslint-disable-next-line no-unused-vars + for ( const key in this.userData ) { object.userData = this.userData; break }; object.layers = this.layers.mask; object.matrix = this.matrix.toArray(); From 8aaaf21494a34c83e4c87066ab7c152941cd1aee Mon Sep 17 00:00:00 2001 From: Benjamin <45743294+Hoodgail@users.noreply.github.com> Date: Tue, 29 Nov 2022 10:48:19 -0500 Subject: [PATCH 4/4] Reverted back to Object.keys over `for loop` --- src/core/Object3D.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/core/Object3D.js b/src/core/Object3D.js index a7563ec4633c42..42eaaee8d685c4 100644 --- a/src/core/Object3D.js +++ b/src/core/Object3D.js @@ -687,9 +687,7 @@ class Object3D extends EventDispatcher { if ( this.visible === false ) object.visible = false; if ( this.frustumCulled === false ) object.frustumCulled = false; if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder; - - // eslint-disable-next-line no-unused-vars - for ( const key in this.userData ) { object.userData = this.userData; break }; + if ( Object.keys( this.userData ).length > 0 ) object.userData = this.userData; object.layers = this.layers.mask; object.matrix = this.matrix.toArray();