Why is my script to add large batches of objects so slow? v2.90
This is due to the material.
As all your objects share the same data, adding the material will add many material slots to the same data. This is visible in the material property of the object: give it a try with n = few objects.
You'll see, for each of them (as same data) n material slots added:

So, remove the line:
object.data.materials.append(mat)

If you want this mat, add it previously to the ico mesh data or add it once after the loop:
mesh.materials.append(mat)

30k objects should be around 1mn (depending on your configuration).