views:

87

answers:

3

I have a powershell script that runs during an msbuild process and validates some stuff by extracting info from log files. The script loads 2 xml files and then does some validation from the data extracted from the log files. Usually the script takes on average 1 to 2 seconds to run. Loading the xml files takes around 800ms to run. Since the script runs 10000 times, it will load these xml files every single time and adding an overhead of loading time of 10000 * .8 sec = 8000 sec.

Is there a way to load these xml files once and then let the script use them for the 10000 times? Urgent help needed.

+1  A: 

Don't know if it's possible in your situation, but when your project has 10.000 components, perhaps the powershell script could extract the component names and locations from the .csproj files and loop over them by itself. Would not only save you the time for loading the XML files over and over again, but also the time for loading the powershell environment 10000 times.

Doc Brown
The only reason powershell script runs each time is to break the build once a violation is done.
bassam
Don't know your total build time, but does that really make sense? For 10000 components, I think it would be more efficient to run the build once, run the validation afterwards, log all broken validation rules, try to fix them and then start the build again.
Doc Brown
Thank you all. But I think I will have to leave as is for now as the amount of information that we get about the violation is more useful than enhancing the performance. We will try to implement a Validation service and then a utility script that tells the service to parse logs and determine violations when a subcomponent has done building.
bassam
+1  A: 

I think you have two choices:

1) Use something besides XML. A plain text file can be parsed much faster for simple key/value pairs, if you don't need the much richer data description of XML.

2) Refactor your build process such that PowerShell controls the MSBUILD for each of the 10,000 components. You can load those XML files at the beginning and reference them as necessary in any of the steps.

Goyuix
+1  A: 

Assumming you have a powershell script that starts like

params([string]$docPath)

$xdoc = [xml] (get-content $docPath)
// do stuff w/ $xdoc

change it to

params([xml]$xdoc)
// do stuff w/ $xdoc 
Scott Weinstein