Refreshing TreeTable too Slow

Hello. I have a tree table with 3 levels in my application. When I refresh it, the time needed is about 20 seconds (tree table has only 7 root rows). I use an algorithm to get the data from the database and build tree table levels. That algorithm has 3 nested “for” loops like:

for(...) { . . for(...) { . . for(...) { . . } } } The problem is not the query (query time is about 3 seconds) so the problem should be drawing the tree table. However, I don’t know what I have to do to solve that problem.

Thank you in advance.