Blog post Technical, Tridion

Eternal Dilemma – Using GetListXml() or GetList() methods to retrieve items from Tridion


If you are a newbie Tridion developer, when you are trying to retrieve Components from Folder or Pages in Structure Group using Core Service API (or TOM.NET API which is similar in implementation), you can use GetListXml() or GetList() methods. There are some differences between these methods which sometimes spark controversy even amongst us veterans. Why?
Well first of all, let’s give a short summary what each method does.

According to API reference documentation the definitions of both methods are:

GetListXml()- Gets a list of items related to specified subject as XML.
GetList() - Gets a list of items related to specified subject as Data Objects.

As Rick Pannekoek explained in his Tridion Stack Exchange question, since Tridion 2011 version, internal (under the hood) processes to retrieve data are:

  • “The Data Access Layer exposes list methods returning (Data) Objects.
  • The XML list methods internally use those Data Object lists and then serialize those Data Objects to R5 list XML (compatible with the XML lists from earlier releases).
  • The Core Service list methods returning objects directly expose the Data Objects. Since this is a remote API, the Data Objects will be serialized too in this case. This happens using the WCF Data Contract Serializer which produces so-called R6 XML (per definition; R6 XML is whatever the WCF Data Contact Serializer outputs when it serializes CM Data Objects).
  • The TOM.NET list methods which return object also internally use the Data Objects and wrap those in TOM.NET objects, which are pre-loaded with all the data available in the Data Objects.

So, only if you access a property which is not available in the list data, a full load will be triggered.”

What this means is that GetListXml() internally calls GetList(). This then begs the question of which one is faster and under which circumstances. Even though GetListXml() internally calls GetList() method, popular opinion is that getting items in XML format is a lot faster than getting them as objects.

Another popular opinion is that even though items are retrieved as a single XML file, the data retrieved is in most cases insufficient, so an additional kind of “full load” of items (with most of the properties) as objects is required. The bottom line for this argument is that retrieving XML and then all items as objects takes more time than getting them as objects in the first place.

To put this argument to the test I performed a series of empirical tests to see which one behaves better and under which circumstances.

So, here are the results:

Premise:

  • Retrieve all Components from a Folder recursively.
  • Number of retrieved items: 78925
  • Number of test repeats: 50
Average time for GetList()67251.33 milliseconds
Average time for GetListXml()36059.90 milliseconds

Conclusion: when retrieving multitude of objects GetListXml() method is more than 80% faster. The conclusion is to retrieve data as XML if you work with thousands of objects and if XML contains all the data you need.

Premise:

  • Retrieve all Components from a Folder recursively.
  • Number of retrieved items: 25
  • Number of test repeats: 50
Average time for GetList()156.92 milliseconds
Average time for GetListXml()141.32 milliseconds


Conclusion: when retrieving a small number of objects (less than 100) GetListXml() method is about 10% faster, which shows that retrieving fewer items takes nearly the same time for both methods.


Graph 1: Degradation of GetList() performance compared to GetListXml() method

The graph above demonstrates the degradation of GetList() method compared to GetListXml(). It is observable that with the increase in a number of retrieved items GetList() method becomes slower and slower, where at around 80.000 items it becomes almost two times slower than GetListXml(). But why is this so if we know that later uses first internally? Shouldn’t retrieving items as XML take more time? Well, not exactly. The case above is valid when items are retrieved over the network. So piping thousands of objects with properties over the network takes considerably longer than just one large XML.

When XML is not enough…

As it happens, in most cases retrieving items as XML does the work, but sometimes it is just not enough. Although XML has a number of properties that can be used as shown in the example below, sometimes they are not enough, therefore forcing you to retrieve them as a list of objects.

<tcm:ListItems ID="tcm:31-2666-2" Managed="10682" xmlns:tcm="http://www.tridion.com/ContentManager/5.0" xmlns:ext="http://www.tridion.com/ContentManager/R5/Extension">
  <tcm:Item ID="tcm:31-17924" Title="EXLRT slider 2" Icon="T16L0P0" Type="16" IsNew="false" IsPublished="false" Modified="2018-11-30T11:00:43" SubType="0" IsShared="false" IsLocalized="false" Lock="0" Trustee="tcm:0-0-0" SchemaId="tcm:31-1283-8" />
  <tcm:Item ID="tcm:31-17925" Title="EXLRT slider 1" Icon="T16L0P0" Type="16" IsNew="false" IsPublished="false" Modified="2018-06-30T11:04:06" SubType="0" IsShared="false" IsLocalized="true" Lock="0" Trustee="tcm:0-0-0" SchemaId="tcm:31-1283-8" />
  <tcm:Item ID="tcm:31-17927" Title="Welcome To EXLRT Collection" Icon="T16L0P0" Type="16" IsNew="false" IsPublished="false" Modified="2019-06-30T10:57:08" SubType="0" IsShared="true" IsLocalized="false" Lock="0" Trustee="tcm:0-0-0" SchemaId="tcm:31-673-8" />
</tcm:ListItems>

Premise:

  • Retrieve all Components from a Folder recursively. Read each Component from XML additionally as object using Read() method
  • Number of retrieved items: 29
  • Number of test repeats: 50
Average time for GetList()5191.45 milliseconds
Average time for GetListXml()211.34 milliseconds


Conclusion: If additional properties besides ID, Title, Type, Modified Date or others are needed, then additional load of each item using Read() in combination with GetListXml() method takes significantly longer than retrieving items using GetList() in the first place.

When the Tridion API hates you…

I mentioned above that using GetList() will retrieve items with most of the properties because even though the items are loaded as objects, some of those properties are null and are accessible only after the item is fully loaded using the Read() method. For example, Metadata, or Content properties of a Component are not available unless retrieved when fully loaded. Is it fair? No, but the world isn’t fair, and neither is the Tridion API! So keep an eye on missing properties. You can check some of the questions on the Tridion Stack Exchange like this one, or this one for more insight on the subject.

Conclusion

You might be wondering what a general conclusion of this article is. Well, it’s up to you. If you like working with XML then, by all means, keep using GetListXml() method. It’s faster and will get you most of the data you need. However, if you need some specific property of an item, one that is not available as a result of the GetListXml() method, then go for GetList(). Double-check that it is available if you use the GetList() method. If it’s not, then you have to read each item using the Read() method. Besides, be aware of the amount of content you are working with. As the graph above shows, there can be significant performance differences based on the number of items retrieved.

If you have any questions, feel free to contact us.

Contact us to discuss your project.
We're ready to work with you.
Let's talk