Chace Fields
Chace Fields

Reputation: 907

How to increase performance of a list with 5000 objects that is returned to a view and output in asp.net mvc?

The app I'm working on has a physician look-up list. It's a simple form field that takes an Id and this look-up will allow the user to view the entire list of physicians and add one to the field. We are loading the list in the controller and then returning the list to the view, where the data is formatted in a table.

<div id="physicians-selection-dialog">
    <table id="list">
    <thead>
        <tr>
            <td>#</td>
            <td>First Name</td>
            <td>Last Name</td>
            <td>Department</td>
            <td>State Lic</td>
        </tr>
    </thead>
    <tbody>
    @foreach (var physician in Model.Physicians)
    {
        <tr><td><button class="list-select" value="@physician.PhysFxId">@physician.PhysFxId</button></td><td>@physician.PhysFirstName</td><td>@physician.PhysLastName</td><td>@physician.PhysDepartment</td><td>@physician.PhysStateLic</td></tr>
    }
    </tbody>
    </table>
</div>

The user clicks a link that displays a jQuery dialog with the above html for all 5k physicians. This works fine, however, it is extremely slow to render. I need to increase the performance but am not certain what I should do?

  1. Should I cache the physician list, so it doesn't need to keep loading the 5k objects every time the view is loaded? That list is being loaded from the DB. This list will never or rarely change, so that isn't a worry.
  2. Is there a way to cache the html output?
  3. Paginate the data, but I think they want a top down list. Faster to scroll than keep clicking next.

How can I increase performance here?

Upvotes: 1

Views: 663

Answers (1)

Erix
Erix

Reputation: 7105

What you should really do is only retrieve the physicians needed from the database in the first place. A list of 5000 items is pointless, nobody is going to look through that.

You can implement a paging system that that passes something like page number, page size, and sort criteria to a stored procedure or data layer method. This method will then only retrieve the applicable items from your DB. You will save DB processing time, network transfer time, Business Object creation time, and rendering time in this way.

Upvotes: 12

Related Questions