Performance of dynamically generated database code in Visual Studio 2012

Status
Not open for further replies.

uviathon

Ars Scholae Palatinae
1,333
I had to write some methods for disabling user accounts using ASP.NET's built-in Membership and Profile classes. I did all the work in VS 2010. I call a webservice using jQuery on page load to retrieve old accounts (have no subscriptions and haven't logged in for the past 3 months). Then I use a jQueryUI Selectable Dialog to choose which accounts to disable, and then call another webservice method to do the actual disabling.

Everything functions properly. I was forced to upgrade to VS 2012 a few days ago, and suddenly the performance of the whole thing has taken a nosedive. It seems, at least in part, to center around database performance, specifically when database access is handled by dynamically generated db access code.

As I mentioned above, the page calls a webservice method in $(document).ready() to get a list of all old accounts that can be disabled. Debugging on my machine, using VS 2010, this page used to load in a few seconds. Now, using VS 2012, it averages about 40 seconds. It still returns all the proper information and functions properly. Here's the webservice method that's called on page load.

Code:
[WebMethod]
[ScriptMethod]
public ArrayList FindIdleUsers()
    {
        int noActivity = Convert.ToInt16(ConfigurationManager.AppSettings["MonthsBeforeUserIsIdle"]);
        ArrayList results = new ArrayList();
        MembershipUserCollection mu = Membership.GetAllUsers();
        foreach (MembershipUser u in mu)
        {
            using (SubscriptionAlertDataTableAdapter adapter = new SubscriptionAlertDataTableAdapter())
            {
               // create instance of this user's profile
               ProfileCommon pc = (ProfileCommon)ProfileBase.Create(u.UserName);
               // only check active accounts
               if (!pc.deactivateAccount)
               {
                  // determine if user has subscriptions
                  SubscriptionAlertDataTable subs = adapter.GetSubsByUserid((Guid)u.ProviderUserKey);
                  if (subs.Rows.Count <= 0)
                  {
                     // check if they haven't logged in within 3 months of today
                     if (DateTime.Compare(u.LastLoginDate, DateTime.Now.AddMonths(-noActivity)) < 0)
                     {
                        results.Add(new IdleUser((Guid)u.ProviderUserKey, u.UserName));
                     }
                  }
               }
            }
        }
        return results;
    }

The code that disables accounts is simple enough.
Code:
     ProfileCommon pc = (ProfileCommon)ProfileBase.Create(username);
     MembershipUser u = Membership.GetUser(username);
     pc.deactivateAccount = true;
     pc.deactivateAccountDate = DateTime.Now;
     pc.Save();

As you can probably tell, the database code for checking active subscriptions is done through ADO.NET objects (don't even get me started; we are slowly transitioning to Entity Framework, but that's not an option for this part of the application at this point). If I comment out that part, so it's not checking for people with active subscriptions, it shaves about 20 seconds off the response time of the method. If I comment out checking the profile if the account is already disabled, it shaves about another 20 seconds off the response time. It used to take only a few seconds for the whole thing to check every account, including subscriptions and profile information. The disabling of accounts used to take less than 30 seconds. Now, it takes at least a minute. It still seems odd, though, because the Membership class also has to grab information from the database using its own code generation, and that works just fine. If I just loop through every user - without worrying about any other criteria - I can find and disable every user in just a few seconds.

There has been no changes to the underlying XSD data models, recently. The only recent change is my migration to VS 2012. Has anyone heard about any performance degradation of dynamically generated database code, especially that used by the ProfileBase class or ADO.NET objects? Is there some step I was supposed to take for VS 2012 to optimize code or something? I didn't do anything like that prior to changing VS versions - I installed VS 2012, opened the solution and continued working where I had left off in VS 2010.
 

uviathon

Ars Scholae Palatinae
1,333
And now I'm more confused. I compiled the code and committed it to our test server, and it runs fine. The full webservice method returns a response in around 5 seconds, and that's checking a copy of the production database, which contains well over 3000 users.

Is there something I can do on my laptop to force VS 2012 to try to optimize the code or something like that?
 

tinyMan

Ars Tribunus Angusticlavius
6,149
Subscriptor++
uviathon":3qf6zlvc said:
Is there something I can do on my laptop to force VS 2012 to try to optimize the code or something like that?

You are running Release builds on your dev machine right? Debug/Checked builds in VS can be much, much slower than Release builds, especially where heavy elements like Entity Framework are involved.

Also, are you using IIS locally on your dev box, instead of running it through IIS Express or Visual Studio's Web Server?
 
Status
Not open for further replies.