U4-10561 - Proposed performance benefit for IsAncestorOrSelf method

Created by Dan Bramall 18 Oct 2017, 08:46:54 Updated by Sebastiaan Janssen 18 Jul 2018, 12:46:40

Currently when calling IsAncestorOrSelf the method checks all ancestors recursively for a matching id:

return other.AncestorsOrSelf().Any(x => x.Id == content.Id);

Particularly when content is deeply nested this will result in a lot of objects being created in memory. It's proposed that comparing the path values instead would be more performant/less memory intensive.

Pull request on the way...


Dan Bramall 18 Oct 2017, 09:30:12

PR: https://github.com/umbraco/Umbraco-CMS/pull/2253

Lee Kelleher 17 Jan 2018, 19:17:40

This is a good performance improvement, saves on traversing up the object tree.

Lee Kelleher 13 Jul 2018, 09:30:54

Created a new PR, rebased and extra commits added (to Dan's original one). https://github.com/umbraco/Umbraco-CMS/pull/2768

Sebastiaan Janssen 18 Jul 2018, 12:46:40

Just to note, a bit of extra work was required: https://github.com/umbraco/Umbraco-CMS/pull/2787

Priority: Normal

Type: Performance Problem

State: Fixed


Difficulty: Normal


Backwards Compatible: True

Fix Submitted: Pull request

Affected versions:

Due in version: 7.12.0


Story Points: