Fast Datastructure Advice

[This is probably a question for advanced scripters who know the underlying mechanics of Lua]

I have created a finite terrain generator which requires lots of maths etc. It crashes when I ask for a reasonble terrain “resolution” (more triangles/regions) at a reasonable size, so I add waits. This, however, makes the code exponentially more slow as settings become more “acceptable”

I tried adding math.random() so it waits only sometimes, but its still too slow.

The article I read to make this used a specifc version of an algorithm which doesn’t store tables inside eachother etc and doesnt use dictionaries (i think) as apparently this made the code as fast as possible, despite the inconvenience of having to indirectly find relevant data in other tables. I have replicated this to some extent.

I have to sacrifice readability/convenience to make this code run in a reasonable timeframe so any advice on what types of datastrucures are faster, things to avoid, good practices etc, maybe theres a better way than using wait to run as many loops as possible without crashing, anything at all that could make code run faster which does lots of maths, loops and table storing is appreciated

The code is very long so i wont post it unless someone’s REALLY REALLY dedicated to maximising my efficiency.

I tried adding math.random() so it waits only sometimes, but its still too slow.

For this I typically use a step yield, i.e;

for Index = 1, 1000 do --1,000 steps.
	if Index % 200 == 0 then task.wait() end --Yield for a single frame every 200 steps.
end

So instead of yielding 1,000 times the numeric loop only yields 5 times.

1 Like