# Scaling performance 🚀 > Quick guide with tips to improve performance of your Tres.js application. We are running WebGL on the browser, which can be quite expensive and it will depend on how powerful the user's device is. To make 3D accessible to everyone, we need to make sure our applications are optimized to run also on low-end devices. This guide will provide some tips to improve the performance of your Tres.js application. ## On-demand rendering By default, Tres.js will render your scene on every frame. This is great for most applications, but if you are building a game or a complex application, you might want to control when the scene is rendered. Otherwise it might drain your device battery 🔋 🔜 đŸĒĢ and make your computer sound like an airplane đŸ›Ģ. Ideally, you only want to **render the scene when necessary**, for example when the user interacts with the scene and the camera moves, or when objects in the scene are animated. You can do that by setting the `renderMode` prop to `on-demand` or `manual`: ### Mode `on-demand`
```vue ``` #### Automatic Invalidation When using `render-mode="on-demand"`, Tres.js will automatically invalidate the current frame by observing component props and lifecycle hooks like `onMounted` and `onUnmounted`. It will also invalidate the frame when resizing the window or changing any prop from the `` component like `clearColor` or `antialias`. The code below updates TresMesh's position-x prop every second, triggering a new render. ```vue ``` #### Manual Invalidation Since it is not really possible to observe all the possible changes in your application, you can also manually invalidate the frame by calling the `invalidate()` method from the [`useTresContext` composable](../api/composables.md#usetrescontext): ::: code-group ```vue [App.vue] ``` ```vue [Scene.vue] ``` ::: ### Mode `always` In this rendering mode, Tres will continously render the scene on every frame. This is the default mode and the easiest to use, but it's also the most resource expensive one. ### Mode `manual` If you want to have full control of when the scene is rendered, you can set the `render-mode` prop to `manual`: ```vue ``` In this mode, Tres will not render the scene automatically. You will need to call the `advance()` method from the [`useTresContext` composable](../api/composables.md#usetrescontext) to render the scene: ```vue ``` ## Dispose resources `dispose()` When you are done with a resource, like a texture, geometry, or material, you should dispose of it to free up memory. This is especially important when you are creating and destroying resources frequently, like in a game. TresJS will automatically dispose of resources recursively when the component is unmounted, but you can also perform this manually by calling the `dispose()` directly from the package: ::: warning To avoid errors and unwanted sideeffects, resources created programatically with the use of `primitives` need to be manually disposed. ::: ```html {2,12} ```