# Perlin noise causes a huge amount of lag

when generating 16x20x16 size chunks I noticed that having a higher octave would cause a minor amount of lag, I just left octaves at 1 and it stopped. but now when I changed the size of the chunk to 16x80x16 there would be a 20 frame drop per chunk generated. The only reason I can see this happening is that the noise function is being called 40 times more per chunk and that disabling the blocks from being created doesn’t seem to change anything either. Any ideas on what I should do?

With blocks being created

without blocks being created(same
amount of lag)

We need to see the code you’re using for this to help you.

here’s the generation module

``````local Generation = {}
Generation.Noise = function(x, y, octaves, lacunarity, persistence, scale, seed)
local value = 0
local x1 = x
local y1 = y
local amplitude = 1
for i = 1, octaves, 1 do
value += math.noise(x1 / scale, y1 / scale, seed) * amplitude
y1 *= lacunarity
x1 *= lacunarity
amplitude *= persistence
end
return math.clamp(value, -1, 1)
end
PART_SCALE = 4
NOISE_SCALE = 100
HEIGHT_SCALE = 40*2

OCTAVES = 1
LACUNARITY = 0
PERSISTENCE = 2
SEED = 12345

amplitude = 100
noiseScale =0.99
local maxheight = 40*4
local function pack(pos:Vector3)
local statement = pos.X..","..pos.Y..","..pos.Z
return statement
end
function Generation.GetBlockName(position:Vector3)
local Surface = (2+ Generation.Noise(position.X,position.Z,OCTAVES,LACUNARITY,PERSISTENCE,NOISE_SCALE,SEED))*HEIGHT_SCALE
return (position.Y<Surface and position.Y <=maxheight and Generation.CheckForCave(position)or position.Y == 0) and "Stone" or nil
end

function Generation.GetBlock(pos:Vector3)
local c =Generation.GetBlockName(pos)
return c and {c,0,{0,0,0},{pos.X,pos.Y,pos.Z},0,true}
end
function Generation.GetChunks(chunks)
local new = {}
for i,v in pairs(chunks)do
for index,coord in ipairs(v) do
for y = 0,maxheight,4 do
local coords = string.split(coord,"x")
local position = Vector3.new(coords[1],y,coords[2])
local block,id = Generation.GetBlockName(position)
id = 0
if  block ~= nil and block ~="Air" then
new[i] = new[i] or {}
local packpos = pack(position)
new[i][packpos] = {block,id,{0,0,0},packpos,i,true}
end
end
end
end
return new
end
``````

after doing some debugging it turns out it perline noise was only causing around 5 frame drops instead of 20