Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to write DataTables from a Web Service into XML?

I'm trying to refactor some slow running code which writes XML using nested loops of several datatables. I read that using linq to write the xml would be faster. I'm not well versed in linq, so I was hoping to get some help here.

Some things I need to mention is that the current architecture uses a webservice which returns data to us in dataTables. We then go through the datatables (iteratively), and there are several which results several nested loops.

example:

dt1 = Webservice.getStuff();

for each (datarow r1 in dt1.Rows) {

   dt2 = Webservice.getMoreStuff(r1[col1], r1[col2]);
   // write out some xml

   for each (datarow r2 in dt2.Rows) {

       dt3 = Webservice.getEvenMoreStuff(r2[col1], r2[col2]);
       // write out more xml 

       for each (datarow r3 in dt3.Rows) {
            // write out more xml 
       }

   }
}

As you can see for obvious reasons, this is terribly slow. Is there a way to speed this up using linq? What would you guys suggest as a more efficient approach to refactor this? I'm sorry if the details are vague...

I appreciate any help anyone could offer.

like image 228
user_rz_jaz Avatar asked Oct 06 '10 14:10

user_rz_jaz


2 Answers

Writing the XML isn't what is slowing you down in this case. That speed should be negligible compared to the time spent making all of the web service calls.

Instead of focusing on the writing of the XML, I would try to figure out how to compress the number of web service calls so you can get all your data at once rather than making nested calls like that.

like image 123
Justin Niessner Avatar answered Oct 01 '22 06:10

Justin Niessner


I am afraid there is no cure for your need. Because I am pretty sure what makes this method slow is not how you write out xml but the way you acquire the data. If there would be any improvment in writing out xml, it would not be in a noticable proportion. I suggest you to revise the way you acquire data. Try to minimize the number of WebService calls.

like image 42
tafa Avatar answered Oct 01 '22 07:10

tafa