How to make my function more efficient?

As you can see i’m working on a voxel game and i’m trying to add as many optimizations as possible (decreasing amount of triangles and my other methods)
I just wanted to ask, if there’s a way to make it even simpler to decrease amount of iterations.
This function will be called (x * y * z) * 6 + (x * y * z) times. Which makes ((x * y * z) * 6 +(x * y * z)) * 2 iterations.
image

I never really have used a Voxel, and I never really use functions, but it looks fine. Optimization and efficiency-wise, if it works, then it looks fine.

I mean the voxel, is really just a plane mesh (4 corners,2 triangles) (1 face)

There’d be no real way to make it more “efficient” if it does what it needs to. :smiley:

1 Like

I remember seeing somewhere that someone suggested instead of having three tables with the need to index three times you just have one like so:

Table[x][y][z]

You do

Table[xyz]

But otherwise remove the first two lines which check and create a voxel if it doesn’t exist and make sure to index voxels that only within pregenerated range for max efficiency. --less indexing and logic checks = more efficient, pretty minor. But you lose a lot of safety checks with this method.

Otherwise like @CommanderRanking If It works don’t bother.

I tested that iterating through dictionaries are way slower than iterating through arrays, so it’s not an option and if you meant multiplying xyz, it’s also not a solution as everything would break at 0th index.

Alright yeah that’s true researching further into it again

But yeah my point still stands with reducing the number of indexing and logic or statements if you really want to go with this micro-optimization.

These questions are interesting but I always end up regretting researching it, always like 1 ms difference for a lot of work.