Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8282197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:17:27+00:00 2026-06-08T10:17:27+00:00

I have stumbled across a very curious issue of poor performance when asp.net MVC

  • 0

I have stumbled across a very curious issue of poor performance when asp.net MVC control is called by jquery $.ajax function. The control performs a database action that takes 403ms, but the total $.ajax call is 3400ms according to Firebug, which is quite a bit of added overhead. I need to optimize the performance but I am not clear where does this overhead comes from.

Here is the code.
In my Controller, I have

 public JsonResult SetSearchResults(Criteria searchCriteria)
 {

       SearchResult myReportsResult = _repository.GetResults(searchCriteria);    

       //the statement above takes 403 ms

       return Json(myReportsResult);
  }





 public  SearchResult GetResults(SearchCriteria searchCriteria)
  {
        SearchResult result = SearchResult();

         DataTable dbResults = _da.GetDBResults(searchCriteria);       


        List<IncidentReportHeader> irs = new List<IncidentReportHeader>();            

        for (int i = 0; i < dbResults.Rows.Count; i++)
        {
            IncidentReportHeader ir = new IncidentReportHeader();

            //populate all the properties of the ir object here,                

            irs.Add(ir);
        }

        result.Reports = irs;       
        return result;        
}

    //models
    public class SearchResult
    {

        private List<IncidentReportHeader> _res;
        private int _numOfPages=0;
        private int _recordsPerPage=0;

        public List<IncidentReportHeader> Reports {
            get { return _res; }
            set
            {
                _res = value;              
            }        
        }           


        public SearchResult()
        {
            _res = new List<IncidentReportHeader>();
        }
    }
}




//db call
   public DataTable GetDBResults(SearchCriteria searchCriteria)
       {
         //add all params to the db object needed for the stored procedure here



            DataTable dt = _db.ExecuteStoredProc("myDB.PACKAGE_NAME.stored_proc", 2000, ref  _spParams, ref _spResultVariables);
           return dt;

}

in my JS

function SearchIncidentReports() {

    //pack the  searchCriteria object here
    var searchCriteria = ...

    var start = new Date().getTime();

    $.ajax({
        contentType: 'application/json, charset=utf-8',
        type: "POST",
        url: myController/SetSearchResults,
        data: JSON.stringify({ searchCriteria: searchCriteria }),
        cache: false,
        dataType: "json",

        success: function (response) {

            var got_data = new Date().getTime();
            var diff1 = got_data - start;
            alert("data loaded in: " + diff1 + " ms");

             // do whatever you need with the data here.  
             // diff1 = 3400ms which is what Firebug shows too

        },

        error: function (xhr, ajaxOptions, thrownError) {
            var result = $.parseJSON(xhr.responseText);
            alert(result.ErrorMessage);
        }

    });
    return false;
}

Another note, when the database call is removed and I populate the object manually, the performance is super fast.

It seems that going from 403ms to 3400ms is plain wrong and clearly has unjustified overhead. Can you please point out what is being done wrong here? It’s pretty bare bones and I can’t really avoid going to the database.

I tried having the Control return the empty set (ActionResult) rather than JsonResult but it had the same issue.

Is this asp.net MVC issue?

Update

I also have an action that returns an Excel file and exactly the same database operation inside it. The file comes back in 410ms and not using $.ajax function. It appears that $.ajax is causing the delay somehow. All I need is to get the data from the database, and normally it’s very fast.

I added the inside of the controller code because someone asked for it, but I will repeat that the inside (yes the total inside of the Controller call) takes 403 ms. Clearly, the issue is not on the server or database call. It seems to me that it is between client and server.

Notes:

  1. In Firebug the total time it took to POST using Action GetResults is 3.54s.
  2. When I navigate to Net->All in Firebug, where the breakdown of the request is listed I see that the largest time is spent waiting (3.5s).

It appears that 3.5s – 403ms time is spent when communicating between server and client, but where and why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T10:17:29+00:00Added an answer on June 8, 2026 at 10:17 am

    I found the issue and the issue IS with the database call. However, the reason I was at first misled is the piece of code that calculates the time difference.

    DateTime start = DateTime.Now;
    
    SearchResult myReportsResult = _repository.GetResults(searchCriteria);  
    
    
    DateTime got_it = DateTime.Now; 
    TimeSpan diff = (got_it - start);
    int diff_ms = diff.Milliseconds;
    

    This code did not give me the correct milliseconds value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying out ASP.NET MVC routing and have of course stumbled across a problem.
I'm mucking about with jQuery AJAX and have stumbled upon an oddity (or rather
I seem to have stumbled across a really weird issue when posting a static
So I have a very odd bug. I stumbled across it when I was
I am using iframes in my page, and have stumbled across a weird issue.
I have always used (typeof variable === function) and I stumbled across jQuery.isFunction() and
I have stumbled across the following issue: Using IIS6, I was trying to run
Im developing a javascript/php/ajax application and have stumbled across some problems. Im confident at
I am learning about LLDP protocol and have stumbled across terms chassis ID and
I've been practicing for an upcoming programming competition and I have stumbled across a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.