Hi,

I'm facing an issue with my application startup memory usage(>200 MB) and is looking for some ways to optimize it.

I'm getting a huge XML from the server at startup with more than 1 million nodes..and Iím parsing it to form a data table(using XMLDataDocument class,loading to DOM and using a pre-defined schema) and later building up a dictionary for manipulation of data by the UI controls.

Steps till building dictionary

1. Pre-defined schema is used to prepare data table
2. XML is loaded into DOM for preparing the data table
3. Data table is parsed to prepare a dictionary
4. The whole process of retrieving data till preparing dictionary is running on a background thread which is initiated from the forms constructor.


The XML structure (AuthorName and Book have one to many mapping,Link node is present if it exists and ID can be empty) and the code for populating the dictionary is given below..

XML:
Code:
<IntrestedBookSet>
<IntrestedBook AuthorName="XXX" Book="YYY" ID="1"/>
<IntrestedBook AuthorName="XXX" Book="AAA" ID="2"/>
<IntrestedBook AuthorName="XXX" Book="BBB" ID=" "/>
<IntrestedBook AuthorName="CCC" Book="YYY" ID="5" Link="tttt"/>
<IntrestedBook AuthorName="CCC" Book="YZY" ID="7"/>
<IntrestedBook AuthorName="XXX" Book="XDY" ID="10"/>
<IntrestedBook AuthorName="CCC" Book="BBB" ID="3" Link="ssss"/>
</IntrestedBookSet>
Prepare Dicitonary:
Code:
Dictionary<string,List<string>> intrestedbooks = new Dictionary<string,List<string>>();
//Get the datatable by using XMLDatadocument methods
Datatable theData = service.GetIntrestedBookSet();
//Prepare the dictionary
foreach(DataRow row in theData.Rows)
{
List<string> books = new List<string>();

if(intrestedBooks.TryGetValue(row["AuthorName"].ToString(),out books))
{
if(!string.IsnullorEmpty(row["Book"].ToString())
  books.Add(row["Book"].ToString());
}
else
{
 books = new List<string>();
intrestedbooks .Add(row["AuthorName"].ToString(),books);
if(!string.IsnullorEmpty(row["Book"].ToString())
  books.Add(row["Book"].ToString());
}
}
Now,after loading the whole set of data into my dictionary, various controls collect information from it at runtime..so cant avoid that.

Let me know if there is any better algorithm to do it.

Thanks in advance,
Mmx