SilentComet & Ne_baba
So you’re building worlds that feel huge but still run on a laptop? Show me the part of your code that’s still making the whole thing lag, and we’ll see if I can shave a few seconds out of it.
Sure thing, here’s the bit that’s still hurting performance. It’s the recursive scene graph traversal in my render loop, written in JavaScript:
```
function renderScene(node) {
if (!node.visible) return;
// Apply node's transform
const transform = node.matrix.clone().multiply(parentMatrix);
// Draw current node
gl.drawElements(gl.TRIANGLES, node.mesh.indices.length, gl.UNSIGNED_SHORT, 0);
// Recurse into children
for (let i = 0; i < node.children.length; i++) {
renderScene(node.children[i]);
}
}
```
The `clone()` and `multiply()` on every frame add up. Let me know what you think.
Just stop cloning a new matrix every frame. Keep a global stack of matrices, push the parent matrix, multiply in place, pop when you’re done. Reuse the same matrix objects for each node, and if a node hasn’t changed, skip its transform entirely. That’ll cut the allocation overhead and the multiply cost, and you’ll see a big drop in CPU time. If you’re still stuck, give me the node layout and I’ll suggest a tighter loop.
That sounds solid, thanks for the heads‑up. I’ll patch the stack approach in the next commit and test the CPU profile. If something still lags, I’ll shoot over the node layout and you can help me tighten the loop. Appreciate the help.
Glad that helps. Keep me posted when you see the numbers, and we’ll fine‑tune the rest. Good luck.
Will do. Talk soon.