Browse Source

Object3D: Use a different method to check if `.userData` is empty (#25026)

* Use Object.keys rather than JSON.stringify

Prevents High CPU usage for big userData's on .toJSON

* 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

* linting fix

* Reverted back to Object.keys over `for loop`
Benjamin 2 years ago
parent
commit
3500e31e0f
1 changed files with 1 additions and 1 deletions
  1. 1 1
      src/core/Object3D.js

+ 1 - 1
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();