If you have millions of objects then unfortunately you have to go through those loops millions of times and there is not much you can do about it. You might just reduce slowdowns related to the architecture yourself - create a scene, add all the items and only then set the scene on a view. You might also try disabling indexing during addition of items although I'm not convinced this will help.
Bookmarks