Skip to content
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

Performance discussion #33

Closed
1 of 2 tasks
alvarosabu opened this issue Dec 9, 2022 · 0 comments
Closed
1 of 2 tasks

Performance discussion #33

alvarosabu opened this issue Dec 9, 2022 · 0 comments
Labels
discussion 💭 help wanted Extra attention is needed

Comments

@alvarosabu
Copy link
Member

alvarosabu commented Dec 9, 2022

Vue reactivity is based on Proxy. This allows Vue 3 to automatically track changes to data objects and update the corresponding DOM elements whenever the data changes.

Since we are rendering a scene and updating it in every frame (60FPS), that means that we are updating the scene 60 times per second. If the object to be updated is reactive, Vue will try to update the scene 60 times per second. This is not a good idea 😅 and will be detrimental to performance, especially in big scenes

Here is a benchmark of the difference between using a Proxy object and a plain object.
proxy-benchmark

Source: Proxy vs Plain Object

To discuss

One real world example is updating an instance for animation:

<script setup lang="ts">
const boxRef: Ref<TresInstance | null> = ref(null)

onLoop(({ _delta, elapsed }) => {
  if (boxRef.value) {
    boxRef.value.rotation.y += 0.01
    boxRef.value.rotation.z = elapsed * 0.2
  }
})
</script>

<template>
  <TresMesh ref="boxRef" :scale="1" cast-shadow>
    <TresBoxGeometry :args="[1, 1, 1]" />
    <TresMeshStandardMaterial v-bind="pbrTexture" />
  </TresMesh>
</template>

Here we are getting the ref for the mesh with the Mesh instance so we can update the rotation, but boxRef remains a Proxy, a solution would be to unref or use a shallowRef since Direct template ref are not available see vuejs/core#1227

I would love to have your input here @wheatjs @kissu @Astanusic

Food for though

https://discoverthreejs.com/tips-and-tricks/#performance

@alvarosabu alvarosabu added help wanted Extra attention is needed discussion 💭 labels Dec 9, 2022
@alvarosabu alvarosabu pinned this issue Dec 9, 2022
@alvarosabu alvarosabu unpinned this issue Mar 10, 2023
@alvarosabu alvarosabu added this to Tres Mar 22, 2023
@github-project-automation github-project-automation bot moved this to Done in Tres Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion 💭 help wanted Extra attention is needed
Projects
Status: No status
Status: Done
Development

No branches or pull requests

1 participant