# Making auto-completion faster?

**URL:** <https://www.ruby-forum.com/t/making-auto-completion-faster/88699>\
**Category:** Rails\
**Created:** [March 13, 2007, 5:40pm UTC](https://www.ruby-forum.com/t/making-auto-completion-faster/88699 "2007-03-13T17:40:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![plambert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9d8465/32.png) [@plambert](https://www.ruby-forum.com/u/plambert)\
**Post date:** [March 13, 2007, 5:40pm UTC](https://www.ruby-forum.com/t/making-auto-completion-faster/88699/1 "2007-03-13T17:40:56Z")

</div>

I just started playing around with the auto-completion  
(text\_field\_with\_auto\_complete) stuff, and it is very nice, but it  
seems a little slow-- it takes about 1 second for the list to appear  
or for an update. The development log says the the SQL query  
completes in 0.01 s, so I’m wondering if there’s some built in delay  
in the ruby/javascript code. Is there some way to configure it to be  
faster? Or is the delay in WEBrick?

Thanks,  
–Paul

---

<div class="post-metadata">

**Author:** ![plambert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9d8465/32.png) [@plambert](https://www.ruby-forum.com/u/plambert)\
**Post date:** [March 13, 2007, 6:01pm UTC](https://www.ruby-forum.com/t/making-auto-completion-faster/88699/2 "2007-03-13T18:01:01Z")

</div>

On Mar 13, 2007, at 12:40 PM, Paul L. wrote:

> I just started playing around with the auto-completion  
> (text\_field\_with\_auto\_complete) stuff, and it is very nice, but it  
> seems a little slow-- it takes about 1 second for the list to appear  
> or for an update. The development log says the the SQL query  
> completes in 0.01 s, so I’m wondering if there’s some built in delay  
> in the ruby/javascript code. Is there some way to configure it to be  
> faster? Or is the delay in WEBrick?
> 
> Thanks,  
> –Paul

There’s a (by default) 0.4s delay in the JavaScript to know that  
you’ve stopped typing. Then there’s the round trip to the server  
(which sounds like it’s local in your case), but you still might have  
a bit of rendering time to include which might be significant if the  
list of completions is long.

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![plambert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9d8465/32.png) [@plambert](https://www.ruby-forum.com/u/plambert)\
**Post date:** [March 13, 2007, 6:21pm UTC](https://www.ruby-forum.com/t/making-auto-completion-faster/88699/3 "2007-03-13T18:21:05Z")

</div>

Thanks! I searched for the 0.4 and found the frequency option which  
(in case anyone else wants to do this) I set like this:

\<%= text\_field\_with\_auto\_complete :answer, :answer\_text,  
{}, :frequency=\>0.1 %\>

That made things faster (though not 4 times faster, because of the  
server  
response time). The downside is that now every keystroke initiates a  
request  
for an update, which might not scale so well if there are lots of  
users.

On Mar 13, 12:59 pm, Rob B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![plambert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9d8465/32.png) [@plambert](https://www.ruby-forum.com/u/plambert)\
**Post date:** [March 13, 2007, 9:22pm UTC](https://www.ruby-forum.com/t/making-auto-completion-faster/88699/4 "2007-03-13T21:22:44Z")

</div>

Paul L. wrote:

> Thanks! I searched for the 0.4 and found the frequency option which  
> (in case anyone else wants to do this) I set like this:
> 
> \<%= text\_field\_with\_auto\_complete :answer, :answer\_text,  
> {}, :frequency=\>0.1 %\>

/Rails Recipes/ covers auto\_complete where the source array is  
preloaded at page fetch time.

That naturally might not fit your situation. One might also think of a  
hybrid that preloads a table and then adds to it dynamically…

–  
Phlip  
[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) ← NOT a blog!!
