Jump to content

Recommended Posts

Posted

Why does assigning this variable significantly slow my program down? If i have the name = cloneinfo.element line commented out the program completes in under a minute. When i enable the line it takes like 2 - minutes to complete. Shouldn't the value be read into memory already when it is assigned to clone info? i'm just reassigning it to a different variable name.

 

var cloneInfo = lbXML
                    .Descendants("Game")
                    .Where(x => (string)x.Element("ID").Value == element.Element("GameID").Value)
                    .Select(x => (x.Element("Title").Value));

 

name = cloneInfo.ElementAt(0);

Posted

Try adding .ToArray() after your select.

You've created a sequence of commands that gets executed each time it tries to find data in it, rather than creating an array/list to search through.

(Linq is funny like that, if you don't execute it to finalize it yourself it does to every time you request data from it)

Posted

Thanks Joyce... unfortunately it is still slow when assigning name.

 

var cloneInfo = lbXML
                    .Descendants("Game")
                    .Where(x => (string)x.Element("ID").Value == element.Element("GameID").Value)
                    .Select(x => (x.Element("Title").Value)).ToArray();
               

name = cloneInfo.First();

Posted

Strange, I can't imagine that really being the case if the initial query isn't too slow.

Did you time the Linq portion seperated from the part where you assign name?

Posted

yeah,

 

This takes about 30 seconds

var cloneInfo = lbXML
                    .Descendants("Game")
                    .Where(x => (string)x.Element("ID").Value == element.Element("GameID").Value)
                    .Select(x => (x.Element("Title").Value)).ToArray();
               

//name = cloneInfo.First();

 

------------------------------------------------------------------------------------------------------------------------------

 

this takes about 3 minutes

var cloneInfo = lbXML
                    .Descendants("Game")
                    .Where(x => (string)x.Element("ID").Value == element.Element("GameID").Value)
                    .Select(x => (x.Element("Title").Value)).ToArray();
               

name = cloneInfo.First();

Posted

yeah, let me clean it up a little for you... I'm working on v2 so i have a lot of stuff that is working but slow commented out trying to upgrade it.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...