Slow performance when initializing AutoComplete

Slow performance when initializing AutoComplete

Trying to apply the AutoComplete bundled with UI 1.8.2 to 280+ input fields on a page. I noticed that the initial rendering of the page is somewhat slow and upon investigation I see that the initialization of the plug-in is the culprit.

The following code takes over 7 seconds to execute in FF 3.6.3 with IE7 taking even longer.

  1. console.time('autocomplete');
  2. $("input[id$='Project']").autocomplete({
  3.     minLength: 3,
  4.     source: function (request, response) {
  5.         $.ajax({
  6.             url: '<%= Url.Action("FetchProjects", "Projects") %>',
  7.             dataType: 'json',
  8.             data: {
  9.                 criteria: request.term,
  10.                 limit: 15
  11.             },
  12.             success: function (data) {
  13.                 response($.map(data, function (item) {
  14.                     var label = item.Id + ' (' + item.Name + ')';
  15.                     return {
  16.                         label: label.replace(new RegExp('(' + $(this).val() + ')', 'gi'), '<strong>$1</strong>'),
  17.                         value: item.Id
  18.                     }
  19.                 }))
  20.             }
  21.         });
  22.     },
  23.     select: function (e, ui) {
  24.         $(this).val(ui.item.Id);
  25.     }
  26. });
  27. console.timeEnd('autocomplete');
Anybody have any idea what the AutoComplete is doing to take so long? It's not like it is loading data during its initialization routine.

Thanks.

- Jason