# Shared vertices performance?

I’m creating a dynamic plane which I’m going to displace with some noise.

I began by generating a mesh with unique vertices, but wanted smooth shading - so i changed it to a plane with shared vertices.

My performance took a HUGE dive - what could be the issue?

``````public static Mesh BuildPlaneMesh(float length, int subdivisions) {
Mesh mesh = new Mesh();
mesh.name = "ScriptedMesh";
List<Vector3> vertices = new List<Vector3>();
List<Vector2> uvs = new List<Vector2>();
List<int> triangles = new List<int>();
List<Vector3> normals = new List<Vector3>();

int numVerticesPerRow = subdivisions * 2 + 1;
float sideLength = length / (numVerticesPerRow - 1);
for (int i=0; i < numVerticesPerRow; i++) {
for (int j=0; j < numVerticesPerRow; j++) {
// building vertices
float xCoord = sideLength * j - (length/2);
float zCoord = sideLength * i - (length/2);
uvs.Add(new Vector2((xCoord + length/2) / length, (zCoord + length/2) / length));

// winding
if (j != numVerticesPerRow - 1 && i != numVerticesPerRow - 1) {
for (int k = 0; k < numVerticesPerRow - 1; k++) {
int[] initialTriangleList =
new int[] { numVerticesPerRow, 1, 0,  1, numVerticesPerRow, numVerticesPerRow + 1 };
foreach (int index in initialTriangleList) {
triangles.Add((index + k) + (numVerticesPerRow * i));
}
}
}
}
}

mesh.vertices = vertices.ToArray();
mesh.uv = uvs.ToArray();
mesh.triangles = triangles.ToArray();
mesh.normals = normals.ToArray();
return mesh;
}
``````

The mesh looks fine and triangles seem to be facing the right way. Once the subdivisions start to go up, i see a huge dive in performance with the current implementation - what could be the issue?

The problem was that I was adding double vertices using the ‘k’ iterator.