question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possible Unnecessary World Matrix Updates on Hidden Objects

See original GitHub issue

I was looking to get some feedback on a huge performance gain I achieved in the forums and it was suggested by @Mugen87 to bring following topic to github.

https://discourse.threejs.org/t/updatematrixworld-performance/3217

This seems to be related to #14138 but I did not want to distract from the PR.

Anyway, my app was suffering from a performance hit from there being far too many world matrix updates on objects (skinned and regular meshes).

I set matrixAutoUpdate to false and manually update when needed. I also set visibility to false on objects a certain distance from camera. I was expecting to have better world matrix performance from at least the visibilty being false but no.

As a test, I added if( !this.visible ){ return false; } to Object3D.updateMatrixWorld. The results were pretty amazing. Performance increased by no less than 50% in my app.

I’m not really sure how to proceed. Obviously I can add one line of code to three.js each release without much of an issue. But, what about other users who have a bunch of invisible objects? I’m sure they wouldn’t mind increased performance.

One thing is though… this only seems to work well since updateMatrixWorld traverses down the object hierarchy. This method may be hurting performance in itself. I’m thinking of a SkinnedMesh with many Bones, or really any object with a large set of children.

So yea, should I bother making a PR to return false on invisible objects when calling updateMatrixWorld or wait till this whole situations regarding the method is resolved?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
inearcommented, Jul 6, 2018

@titansoftime Thank you so much for this advice! I got huge performance boost when adding this visibility-test. I use many groups of instanced geometries (rendering lot’s of objects tied to notes in a musical score) where all positions are calculated in the shader, so need to manually cull all groups outside the frustum. Using visible instead of add/remove was lighter and smoother when keeping the scene-graph intact. I also switch visibility on/off when rendering different post-effects like glow.

I used this way of overriding the updateMatrixWorld prototype so I don’t have to fork and patch:

(function () {
      let _updateMatrixWorld = THREE.Object3D.prototype.updateMatrixWorld
      THREE.Object3D.prototype.updateMatrixWorld = function () {
        if (!this.visible) {
          return
        }
        _updateMatrixWorld.apply(this)
      }
    })()
4reactions
takahiroxcommented, Jun 25, 2018

I’ve been thinking the same optimization, skipping world matrix calculation for invisible object and its children in .updateMatrixWorld(). If I’m right, .updateMatrixWorld()'s main purpose is to update nodes under a rendered scene in renderer. So it’d be ok for that purpose to skip them because invisible objects won’t be rendered.

Probably we need to add ‘skip invisible objects’ argument to .updateMatrixWorld() and set it to false as the default not to break the compatibility. Some users may use the method in their user code and expect all node under an object will be updated regardless of their visibility.

Read more comments on GitHub >

github_iconTop Results From Across the Web

UpdateMatrixWorld Performance - Questions - three.js forum
Hidden objects are considered “pollution” in three.js. github.com/mrdoob/three.js · Issue: Possible Unnecessary World Matrix Updates on Hidden ...
Read more >
Unpacking the Hidden Meanings in The Matrix Resurrections
From the red/blue pill symbolism to the trans allegory, McKenzie Wark muses on the real-life narratives surrounding the simulated world of The ...
Read more >
Kodi 19.5 Matrix – New Features, Download, and Install Guides
Kodi 19.5 Matrix is officially out and now available for download on all the supported devices such as Amazon Fire Stick, FireStick 4K,...
Read more >
What Is Object Permanence According To Piaget?
Object permanence means knowing that an object still exists, even if it is hidden. It requires the ability to form a mental representation...
Read more >
Matrix Table Question - Qualtrics
The Constant sum variation allows respondents to allocate resources among the items in each row. As the respondent provides answers, the total resources...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found