Performance - GetChildren vs GetBySegment
GetChildren is a decent method that is also cached in the background. But if you have 1000s of children you will get some performance hits. Another good option if you are only searching for a single content item is to use GetBySegment method. This one works well with large amounts of children with excellent performance.
I tried it on folder that has 13000+ children (yes, bad idea) and these were the results when running on local machine
- GetChildren
17.857sforeach (var folder in ContentRepository.GetChildren<ContentFolder>(parent)) { if (folder.Name == customerId) { ... } }
- GetBySegment
0.147svar customerFolder = ContentRepository.GetBySegment(parent, customerId, LanguageSelector.AutoDetect());
So that's a pretty huge performance gain by more than a factor 100. Hope it helps someone out there to pick the right tool for the job.
Few children => GetChildren
Many children => GetBySegment or Episerver Find...
Happy coding everyone!
Comments