Gwendalin Posted September 17, 2020 Share Posted September 17, 2020 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); Link to comment Share on other sites More sharing options...
Cheshire Posted September 17, 2020 Share Posted September 17, 2020 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) Link to comment Share on other sites More sharing options...
Gwendalin Posted September 17, 2020 Author Share Posted September 17, 2020 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(); Link to comment Share on other sites More sharing options...
Cheshire Posted September 17, 2020 Share Posted September 17, 2020 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? Link to comment Share on other sites More sharing options...
Gwendalin Posted September 17, 2020 Author Share Posted September 17, 2020 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(); Link to comment Share on other sites More sharing options...
Cheshire Posted September 17, 2020 Share Posted September 17, 2020 Jeebidy Christmas. Do you happen to have a reproducible example? Â Can't promise I can look at it right now. But that doesn't sound right. Link to comment Share on other sites More sharing options...
Gwendalin Posted September 17, 2020 Author Share Posted September 17, 2020 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now