U4-8840 - Perf tweak for IsDescendant

Created by Murray Roke 11 Aug 2016, 05:51:11 Updated by Murray Roke 11 Aug 2016, 05:55:32

Hi The "Path method" below for determining IsDescendant is about 14 times faster than the one in umbraco "Ancestor method" below (assuming the testing methodology is valid and doesn't get compiler optimised away, but it should be faster)

	using (MiniProfiler.Current.Step("Path method"))
	{
		for (int i = 0; i < 100000; i++)
		{
			overviewTab.Selected = current.Path.StartsWith(overview.Path);
		}
	}
	using (MiniProfiler.Current.Step("Ancestor method"))
	{
		for (int i = 0; i < 100000; i++)
		{
			overviewTab.Selected = current.Ancestors().Any<IPublishedContent>((Func<IPublishedContent, bool>)(x => x.Id == overview.Id));
		}
	}

Change would be this line: https://github.com/umbraco/Umbraco-CMS/blob/c4400a20d6ae9df6faac4756050905ba7228d579/src/Umbraco.Web/PublishedContentExtensions.cs#L851

Comments

Priority: Minor

Type: Performance Problem

State: Submitted

Assignee:

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted: Inline code

Affected versions:

Due in version:

Sprint:

Story Points:

Cycle: