How to optimize this minecraft written in javascript

I have this example of a optimized code:


And this another which is the want that I want to optimize:

v3 mod 1 (4.2 MB)

This are the scripts: (168.5 KB)
This the main file:
index.html (12.7 KB)

Capture of that code here:

Its possible? Sorry my impertinence and thanks for help anyway!

Everything is. Could you explain what the code is doing and which part specifically is blocking you?

For optimising CPU - you can run your app in the browser, then when it’s running, open devtools Performance tab and press the recording circle on the top-left. Let it run for 5-10 seconds and stop the recording. Then in the bottom tab of the performance snapshot click Bottom-Up and sort the list by Total Time. This will show you step by step which functions take most time to run on the CPU - try either removing them or minimising their impact as much as possible, caching whatever’s cache-able etc.

For optimising GPU - make sure you’re using instancing whenever possible, especially in such minecraft-like games. Make sure your textures are as tiny as viable. Make sure you’re using cheap materials most of the time, use MeshStandardMaterial only when necessary - starting from MeshBasicMaterial (for non-lit things), MeshLambertMaterial, MeshPhongMaterial, MeshStandardMaterial, MeshPhysicalMaterial (super-rarely needed.)

1 Like

Optimising both, CPU and GPU, specifically the CPU for avoiding neckbottles. I cant send the files of the optimized game, but, this is running at 10fps when I put more than 30 on render distance input and 1 on chunksize, so… what can i do? sorry my bad english…

Hi, I had written a mini example using my own library that uses instancedMesh + frustum culling (so the gpu should work less). Could this be useful to you?

Maybe instantiating as many instancedMesh, as many chunks could be a solution?

Better than my minecraft which i want to optimize, but i need a game optimized like like this:


And this render a fewer short render distance, but anyway, thanks…

In addition to what @mjurczyk said:

I ran the profiler on your app:

Right now, raycasting is taking the vast majority of your frame time. So that’s something you might want to optimize first.

I see you already are using instancing per tile type… That’s a good optimization.

I think the next level up in complexity is to use hand built geometries and greedy meshing to reduce the polygon counts, and remove interior faces on your meshes.
You combine that with a chunk base generation approach to generate single geometries per chunk, and then maintain a visible set of those chunks.



VoxelJS: Chunking Magic

1 Like

Okay, a long past time ago i tried to merge only the surface of the cubes, and the example:
Doesn’t eliminate the unuseful cube’s surface, instead using hidden methods, and, with respect your article, it means it tries the same method?

I think so yes.

The images are that:

So, i need performance on hritik’s minecraft or random world genetion in this mc. Dont want to hurry up.

Edit 1: Anyway, I will try to reduce the raycaster…

Edit 2: IDK How… >_<’

Edit 3: I, at least, deleted raycast without the function of place or remove blocks, here is the result:

v3 mod 1 (4.2 MB)

1 Like

EDIT 4: I compared both of scripts and these of them have different performance score. The HritikRC’s Minecraft render slower than the script without trees and water, and I tried to debug with the ‘performance’ window, but only appears the main loop without any command to quit or place for more performance… Any solution?
There is my file:
v3 mod 1 (4.2 MB)
And this is the another: