Improve fractal noise function

I am trying to improve this code without having to make the terrain “borring”, so I would need some way to optimize this code to make it run faster, because right now it takes 0.9 seconds to generate a heightmap for 3 tiles. Which is way to much when the terrain is infinite and generated on the run.
Here is how I run the code:

			if (perlin == null) {
				perlin = new PerlinNoise(Seed);
			mountains = Mathf.Max(0f, perlin.FractalNoise2D(worldPosX+250, worldPosZ+250, Octaves, mountainFrq, 0.5f) - 0.1f) * 1.5;
			plain = perlin.FractalNoise2D(worldPosX-250, worldPosZ-250, 1, groundFrq, 0.4f) + 0.3f;

Here is the function:

	public float FractalNoise2D(float x, float y, int octNum, float frq, float amp)
		float gain = 1.0f;
		float sum = 0.0f;
		for(int i = 0; i < octNum; i++)
			sum += Noise2D(x*gain/frq, y*gain/frq) * amp/gain;
			gain *= 2.0f;
		return sum;

Full code noise code: New Perlin Noise -

You can create worker threads, yes. The process is similar to using co-routines. Either way, you’ll need to insert yields/waits into the nested loop of sampling checks such that only N% of the whole job is done per frame. This means your terrain object will not be “ready” for several frames after requesting it. Your game must accommodate this shortcoming by loading terrains before they’ll become visible / necessary.