Last post Oct 09, 2017 09:33 AM by Cathy Zou
Sep 29, 2017 11:24 AM|1jus|LINK
I'm trying to speed up a hierarchical tree builder with LINQ, this is what I have but it takes ages for trees that are thousands deep! Any tip on speeding this up at all?
void TreeBuilder(IEnumerable<Tree> data, int? id = null)
var items = data.Where(d => d.parentId == id).OrderBy(o => o.id);
foreach (var item in items)
Sep 29, 2017 12:00 PM|PatriceSc|LINK
Thousands deep really ? How many rows do you finally return? What is your db? In SQL Server you could consider using https://technet.microsoft.com/en-us/library/ms186243(v=sql.105).aspx or https://docs.microsoft.com/en-us/sql/relational-databases/hierarchical-data-sql-server
You could also consider to expand each node as needed. Do you really need to get the full tree especially if it is really that complex...
Sep 29, 2017 12:42 PM|1jus|LINK
It varies per team but 3000 is not uncommon! MS SQL Server
The stakeholders want to see the whole tree!
Oct 09, 2017 09:33 AM|Cathy Zou|LINK
From your description, You get result you want correctly
Then you want know how to improve the Efficiency of the piece of code.
As far as in know, you code has high efficiency yet. so there is no need for you to figure out a way to speed it up: