A quick comparsion between FindPagesWithCriteria and a recursive GetChildren

August 27, 2009

On the project I’m working on at the moment there are plans to do a lot of page retrieving based on categories. My initial thought was to retrieve all pages for that section and to the filtering in memory. Possibly with some pre-filtered and cached collections to speed it up, but since the categories in this case can be combined quite freely, the hit rate on this cache would probably be quite low. Reading Steve’s article about FindPagesWithCriteria and Performance I decided to do some quick unscientific tests on the differences between using FindPagesWithCriteria and a recursive GetChildren implemented as shown below using LINQ filtering to select categories.

public static IEnumerable<PageData> GetDescendants(PageReference pageLink)
  foreach (PageData page in DataFactory.Instance.GetChildren(pageLink))
    yield return page;
    foreach (var child in GetDescendants(page.PageLink))
      yield return child;

I ran my test against EPiServer CMS R2 Sp2 on a local virtual machine running IIS7 with a local SQL2008 server. The test were run both with a full page cache and with a completely empty page cache. No specific caching was done at my end. I also include test runs sorting the list and leaving the list as returned and just retrieving the first 20 pages to simulate paging. Paging was done using the LINQ Take expression for both types. The category selection was done against two mandatory categories and the pages was placed in a three level deep structure with a maximum of 50 children per page. The pages and their categories were randomly generated using the Content Generator that can be found on EPiCode, but I had a quite low number of different values resulting that about every fourth page matched my criteria. Each test was run 10 times showing the average time is in seconds rounded to 2 significant numbers.

Setup GetChildren FindPagesWithCriteria
Number of pages Sorting Paged Cached No Cache Cached No Cache
100 Yes Yes < 0.01 0.15 0.03 0.10
No Yes < 0.01 0.14 0.03 0.10
No No < 0.01 0.15 0.03 0.10
500 Yes Yes 0.02 0.57 0.02 0.30
No Yes <0.01 0.02 0.02 0.30
No No 0.02 0.55 0.02 0.30
10000 Yes Yes 0.40 14 0.60 6.1
No Yes <0.01 0.02 0.38 6.0
No No 0.54 14 0.38 5.6

A few comments about the results:

  • FindPagesWithCriteria and GetChildren has a non significant performance difference for small to medium data sets in most scenarios
  • FindPagesWithCriteria is faster that GetChildren when it comes to large data sets when the pages aren’t cached.
  • Only getting the first page when not sorted makes the LINQ query very fast but it’s probably not a very realistic scenario.
  • Adding sorting or paging doesn’t affect FindPagesWithCriteria significantly.
  • In real life the cache scenario is probably somewhere between full and empty.
  • My setup doesn’t include any network latency
  • My setup only shows how a single user scenario looks, I should re-run these scenarios under load

As I noted, this was a very unscientific test but at least it gave me a bit of inspiration and confidence on what approach I would pursue, hope it was of some use for you!

4 Responses to “A quick comparsion between FindPagesWithCriteria and a recursive GetChildren”

  1. Daniel Berg Says:

    Interesting comparison! Keep up the good work. :)

  2. Patrik Akselsson Says:

    Good article.

    I did a similar comparison on my own a while ago and found that the performance difference of fpwc and GetChildren was very dependent on the hit rate of the query. With low hit rates, FPWC was way faster, especially with an empty cache. This is expected since GetChildren has to load all pages on the web server, whereas FPWC only needs to load those that match the criteria.

    It would be very interesting if you could run the tests with different hit rates, eg with 0,1% and 1% of all pages matching the criteria.

  3. I’ve made a similiar comparison and made the conclusion that FPWC really starts to hurt you when you need more than 1 criteria. My implementation of recursive GetChildren did not suffer from this hardly at all.

    Sorting in GetChildren doesn’t have to hurt you if you do it right and work on a relative small result set <1000.

    Thats my observations on the subject.

  4. […] A quick comparsion between FindPagesWithCriteria and a recursive GetChildren Share and Enjoy: […]

Comments are closed.

%d bloggers like this: