auto-complete speed

Hello.

I have created my first auto-complete fields (text_field_with_auto_complete) and I find the feature a little slow. It takes about a second to see the values pop up on screen. I have tried to play with the :frequency option but I don't see any appreciable difference with anything I do to increase the speed of the feature.

Any ideas?

Thanks

Hi,

Check your database query speed (Check your development.log). If the database retrieval speed is less, it might bog down the auto-complete popup. Add appropriate indexes if that is the case.

Cheers,

Ganesh Gunasegaran.

SageWork(http://www.sagework.com) Simplify IT

Will check into that. Thanks.

Pepe

pepe wrote:

Will check into that. Thanks.

Pepe

Do as little to respond to the auto-complete request. For example, if you use sessions, turn them off for that request. Pull the results from a cache if you can.

Certainly also avoid complex SQL queries like table joins and eager loading to get the content of the auto-complete field. And as mentioned be absolutely sure that any field used in the WHERE clause is indexed on the database table.

I have actually tried pretty much everything I could with my limited knowledge of RoR. One thing I did was to store the results of the queries in arrays the first time they were loaded and then use the arrays instead of going to the table again. I have not noticed any difference in speed in that case. One reason might be that my test tables don't have much data.

Thank you for the insight.

Pepe

The query is almost as simple as could be. There is an :order clause but there is an index on the field I sort by:

  def self.get_codes     return MyModel.find(       :all,       :select => 'code',       :order => 'code'     ).collect {|row| row.code}   end

Thanks.

Pepe

pepe wrote:

The query is almost as simple as could be. There is an :order clause but there is an index on the field I sort by:

  def self.get_codes     return MyModel.find(       :all,       :select => 'code',       :order => 'code'     ).collect {|row| row.code}   end

Thanks.

Pepe

Is this a development environment? If so, in development mode, Rails does a bunch of work on every request, such as reloading all of the classes, which doesn't happen in a production environment.

Try starting your server in production mode (such as mongrel_rails start -e -production). You'll need to edit database.yml to point the production config to your dev database, or set up a production db.

At any case if you doing ajax request to server autocomplete WILL be slow. You need to look into AutoCompleter.Local if you have limited number of options (more than hundred will be overload).

I am aware of the difference in speed between development and production environments. You're right that in production it should be faster. In addition I am running WEBrick, not Mongrel in my machine. You're right, I should switch between environments and see what the difference might be in production mode and installing Mongrel might also help.

Thanks.

Pepe

I new that I could use Javascript to hold the values and make the process faster by letting the browser itself handle the requests but I am not an expert in web development and I know the minimal Javascript to go by. One thing I don't want to do is hard code the values in a Javascript array like this example shows: http://github.com/madrobby/scriptaculous/wikis/autocompleter-local

Would it be possible to get some information as to how to load a Javascript array with the data from model when the action is first invoked? That would probably be the best way to go.

Thanks!

Pepe

Hi Pepe,

The example that you link to,

http://github.com/madrobby/scriptaculous/wikis/autocompleter-local

looks like what you want, except that you don't want to hard code the array in javascript. I would suggest that you save the information that you fetch from your database in a javascript array and then use the local autocompleter from above.

For example, let's say that you want to autocomplete bands like in the local autocompleter example. You might have fetched all your band names in to the variable @band_names, with something like:

@band_names = Band.all.collect {|b| b.name }

And then in your view you can use this javascript to set the autocompleter array (I'm assuming you are using erb templates):

var bandsList = [<%= @band_names * (", ") %>]

Hope this helps.

Regards, Philip Bruce

You may already be doing this but a spinner can help overcome a second or two of querying. Its a border-line putty/duct tape fix but works.

Philip Bruce wrote:

The speed (or lack of) I'm noticing is during my own testing. I just would like it to be instantaneous so when somebody types a letter the list comes up right away instead of waiting for about a second or so. My test tables contain very little information (4 or 5 records in most cases) but I still have to wait for that second or so.

Thank you for the input, though.

Pepe