20% render() performance boost Part 2 (cache attribute names array): avoid 4x object allocation in Renderer._renderObjectDirect()#33111
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
|
I agree we should get rid of |
|
Closing in favor of #33113. |
Unfortunately, a lot of code does not use the set/get method interface but directly access the internals of As an alternative, one could also consider a less dynamic solution and introduce We could also go one step further and treat |
Related issue: #33107
This is Part 2 of this PR.
This updates
BufferGeometrysuch that attribute names are cached. This allowsNodeMaterialObserver.equals()to avoidObject.keys(attributes)being called 2 times per mesh per render.Object.keys()is expensive in tight loops.What I really think
BufferGeometry.attributesshould really be a dedicated class, likeclass BufferGeometryAttributes { ... }. It would be much cleaner to maintain a cached attribute names array (like this PR is doing) internally inside aBufferGeometryAttributesclass instead of wrapping theBufferGeometry.attributesobject in aProxyto do the same thing.I only wrapped the
BufferGeometry.attributesobject in aProxyfor this PR to get the ball rolling on this, but I think a dedicatedBufferGeometryAttributesclass would be better. That way, direct access to the internal object would not be available, and attributes would be added/fetched viasetAttribute()andgetAttribute().