DHTMLX grid cell takes time to close

When i try to expand the grid it open it 3 seconds but when it close the grid it takes more than 10 secs to close the grid

Did you try to use the expandAll()/collapseAll() methods?:
https://docs.dhtmlx.com/api__dhtmlxtreegrid_collapseall.html
https://docs.dhtmlx.com/api__dhtmlxtreegrid_expandall.html

If the problem still occurs for you please, provide a complete demo, where the problem can be reconstructed.