Kyle Kingsbury A Sitecore web development blog!

A faster IsDerived Extension Method

A

If you have been around Sitecore development long enough, you have undoubtedly run into the extension method ‘IsDerived’. This extension method allows developers to easily determine whether an item inherits from a specific base template; the template can be anywhere in the inheritance chain. This opens up a lot of possibilities for developers to customize the inheritance chain for their templates. For instance, it allows multiple sites to inherit from a single template, allowing each site to provide their own standard values (in the Helix world, the Feature modules would provide the single template, with each Project inheriting this template).

In recent performance testing for a project I was working on, I noticed that under load, the IsDerived extension method as originally written was taking about 30-60ms per request (again, this is under load). While not extremely high, it was higher than we were comfortable with and any tweaks that we could make would be beneficial in the long-term, especially when code like the IsDerived extension method is so widely used.

Below you can find the updates to the IsDerived extension methods that I came up with that reduced the time taken under load – in our tests, the time per request under load was negligible.

This should be a drop-in replacement for your existing extension methods. Give it a try and let me know how it worked for you in the comments!

Add comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

By Kyle Kingsbury
Kyle Kingsbury A Sitecore web development blog!
Sitecore MVP 2019 - Technology

Recent Posts

Tags