Skip to content

Commit 3e77c57

Browse files
authored
SSAOPass: Replace visibility cache Map with an array for improved performance (#31453)
* SSAOPass: Replace visibility cache Map with an array for improved performance * SSAO: review comment * SSAOPass: review comment #31453 (comment)
1 parent 297385a commit 3e77c57

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

examples/jsm/postprocessing/SSAOPass.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class SSAOPass extends Pass {
139139
*/
140140
this.maxDistance = 0.1;
141141

142-
this._visibilityCache = new Map();
142+
this._visibilityCache = [];
143143

144144
//
145145

@@ -489,27 +489,28 @@ class SSAOPass extends Pass {
489489

490490
scene.traverse( function ( object ) {
491491

492-
cache.set( object, object.visible );
492+
if ( ( object.isPoints || object.isLine || object.isLine2 ) && object.visible ) {
493493

494-
if ( object.isPoints || object.isLine ) object.visible = false;
494+
object.visible = false;
495+
cache.push( object );
496+
497+
}
495498

496499
} );
497500

498501
}
499502

500503
_restoreVisibility() {
501504

502-
const scene = this.scene;
503505
const cache = this._visibilityCache;
504506

505-
scene.traverse( function ( object ) {
507+
for ( let i = 0; i < cache.length; i ++ ) {
506508

507-
const visible = cache.get( object );
508-
object.visible = visible;
509+
cache[ i ].visible = true;
509510

510-
} );
511+
}
511512

512-
cache.clear();
513+
cache.length = 0;
513514

514515
}
515516

0 commit comments

Comments
 (0)