-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
Removed unnecessary string concatanations to reduce GC activity #14568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,7 +111,14 @@ function WebGLRenderer( parameters ) { | |
| _currentRenderTarget = null, | ||
| _currentFramebuffer = null, | ||
| _currentMaterialId = - 1, | ||
| _currentGeometryProgram = '', | ||
|
|
||
| // geometry and program caching | ||
|
|
||
| _currentGeometryProgram = { | ||
| geometryID: null, | ||
| programID: null, | ||
| wireframe: false | ||
| }, | ||
|
|
||
| _currentCamera = null, | ||
| _currentArrayCamera = null, | ||
|
|
@@ -701,13 +708,14 @@ function WebGLRenderer( parameters ) { | |
| state.setMaterial( material, frontFaceCW ); | ||
|
|
||
| var program = setProgram( camera, fog, material, object ); | ||
| var geometryProgram = geometry.id + '_' + program.id + '_' + ( material.wireframe === true ); | ||
|
|
||
| var updateBuffers = false; | ||
|
|
||
| if ( geometryProgram !== _currentGeometryProgram ) { | ||
| if ( geometry.id !== _currentGeometryProgram.geometryID || program.id !== _currentGeometryProgram.programID || material.wireframe !== _currentGeometryProgram.wireframe ) { | ||
|
|
||
| _currentGeometryProgram = geometryProgram; | ||
| _currentGeometryProgram.geometryID = geometry.id; | ||
| _currentGeometryProgram.programID = program.id; | ||
| _currentGeometryProgram.wireframe = material.wireframe; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, makes sense! Should this be address in this PR or another PR? I already removed the branch.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think another PR is fine.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can do the change locally 👌
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, instead of this.. _currentGeometryProgram.geometryID = geometry.id;
_currentGeometryProgram.programID = program.id;couldn't it just be... _currentGeometryProgram.geometry = geometry;
_currentGeometryProgram.program = program;
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: If you wanna do, you should clear |
||
| updateBuffers = true; | ||
|
|
||
| } | ||
|
|
@@ -1107,7 +1115,9 @@ function WebGLRenderer( parameters ) { | |
|
|
||
| // reset caching for this frame | ||
|
|
||
| _currentGeometryProgram = ''; | ||
| _currentGeometryProgram.geometryID = null; | ||
| _currentGeometryProgram.programID = null; | ||
| _currentGeometryProgram.wireframe = false; | ||
| _currentMaterialId = - 1; | ||
| _currentCamera = null; | ||
|
|
||
|
|
@@ -1455,7 +1465,9 @@ function WebGLRenderer( parameters ) { | |
|
|
||
| var program = setProgram( camera, scene.fog, material, object ); | ||
|
|
||
| _currentGeometryProgram = ''; | ||
| _currentGeometryProgram.geometryID = null; | ||
| _currentGeometryProgram.programID = null; | ||
| _currentGeometryProgram.wireframe = false; | ||
|
|
||
| renderObjectImmediate( object, program, material ); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,10 +67,30 @@ function WebGLRenderState() { | |
| function WebGLRenderStates() { | ||
|
|
||
| var renderStates = {}; | ||
| var hashCache = {}; | ||
|
||
|
|
||
| function get( scene, camera ) { | ||
|
|
||
| var hash = scene.id + ',' + camera.id; | ||
| var hash; | ||
|
|
||
| if ( hashCache[ scene.id ] ) { | ||
|
|
||
| hash = hashCache[ scene.id ][ camera.id ]; | ||
|
|
||
| if ( hash === undefined ) { | ||
|
|
||
| hash = scene.id + ',' + camera.id; | ||
| hashCache[ scene.id ][ camera.id ] = hash; | ||
|
|
||
| } | ||
|
|
||
| } else { | ||
|
|
||
| hash = scene.id + ',' + camera.id; | ||
| hashCache[ scene.id ] = {}; | ||
| hashCache[ scene.id ][ camera.id ] = hash; | ||
|
|
||
| } | ||
|
||
|
|
||
| var renderState = renderStates[ hash ]; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly
wireframecomparison should be?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you saying that checking
true !== undefinedis slower thantrue !== false?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope.
_currentGeometryProgram.wireframeistrue/falsenow butmaterial.wireframecan beundefinedbecause someMaterials don't have.wireframe, thenundefined !== falsewill befalse.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.