Ok, what I suspected is correct. When adding cubes of different materials to the same mesh, with keepMaterial set to true, the length of vertices increases so much that it takes an year to loop.
*Important Note:* In the main mesh (where i add all the cubes to it), if i set its material to null, the loop never ends and the length of vertices keeps increasing till its max (21678) But, if i set a material to it, the loop only takes a minute and the length of vertices at the beginning stay at 36, but only at the end they increase till their max. (will post the class later)
