Easily monitor the performances of your @react-three/fiber application. r3f-perf.js is 6.23 KB.
Add the Perf component anywhere in your Canvas. |
yarn add --dev r3f-perf
headless?: false, // Without UI. See Headless section
showGraph?: true // show the graphs
chart?: {
hz: 60, // graphs refresh frequency parameter
length: 120, // number of values shown on the monitor
}
colorBlind?: false // Color blind colors for accessibility
trackGPU?: true // show a graph of the GPU
trackCPU?: false // show a graph of the CPU (Experimental as it should require a server, so might not be relevant)
openByDefault?: false // show more informations by default
className?: false // override CSS class
position?: 'top-right'|'top-left'|'bottom-right'|'bottom-left' // override position, default is top-right
import { Canvas } from '@react-three/fiber';
import { Perf } from 'r3f-perf';
<Canvas>
<Perf />
</Canvas>;
Usage without interface : headless mode
import { Canvas } from '@react-three/fiber';
import { Perf, usePerf } from 'r3f-perf';
const PerfHook = () => {
const { gl, log } = usePerf();
console.log(gl, log);
return null;
};
export default function App() {
return (
<Canvas>
<Perf headless />
<PerfHook />
</Canvas>
);
}
The tool work with any server side rendering framework. You can try with Next and @react-three/fiber using this starter : https://github.com/pmndrs/react-three-next
- Convert all DOM text to shader to increase the refresh rate
- Buffer frame and Forward rendering differenciation in the "calls" section of the UI
- Postprocess shaders differenciation
- Deep analytics about the shaders (list the types of material/shader)
- Lights informations in the scene
- Show the number of items receiving and casting shadow in the scene
- Add an audit button to find what consume the most CPU/GPU in the app for every loop