background preloader

Schtroumpf

Facebook Twitter

JavaScript Trie Performance Analysis. After my last post discussing dictionary lookups in JavaScript the unanimous consensus seemed to be that utilizing Trie would result in additional space savings and yield performance benefits. A Trie is a relatively simple data structure. At its simplest form you’re building a tree-like structure where each final leaf results in a complete word. This allows for some very efficient use of file size – reducing common prefixes in words quite easily. I looked through a number of JavaScript Trie solutions and yet was not terribly pleased with them. I’ve dumped my work-in-progress JavaScript Trie Generator up on Github (note that it requires Node.js to run).

Generating a Trie The basic Trie generation functionality is as follows (note that I use ’0′ or ‘$:0′ to indicate a complete word): Optimizing the Structure While this is fine I wanted to go a step further. Code posted by Dave Ward Possible Optimization The code for optimization: There’s still room for some additional improvement, though. Client-Side Autocomplete [SOLVED] (Page 1) - AJAX and RJS. Solved! … eter-local ^^ That takes care of client side. I also figured out how to populate other fields via some dom manipulation and a hash of hashes representing my objects. First I needed to parse my ActiveRecord objects into hashes, so I made a pair of simple methods which publish only the attributes I need (to_json proved to be overkill for this) I put this in script tags in the body of my html: var names_for_autocomplete = $H(people_objects).keys()//-> var names_for_autocomplete = ['John','Mary'] new Autocompleter.Local('autoinput', 'results', names_for_autocomplete, { }); Then I hook into the text inputs onBlur event and dig into my object hash And Voila!

Client side autocomplete that is blazing fast and populates multiple fields! Enjoy. Building Fast Client-side Searches. Yesterday we released a new people selector widget (which we’ve been calling Bo Selecta internally). This widget downloads a list of all of your contacts, in JavaScript, in under 200ms (this is true even for members with 10,000+ contacts). In order to get this level of performance, we had to completely rethink how we send data from the server to the client. Server Side: Cache Everything To make this data available quickly from the server, we maintain and update a per-member cache in our database, where we store each member’s contact list in a text blob — this way it’s a single quick DB query to retrieve it. We can format this blob in any way we want: XML, JSON, etc. Whenever a member updates their information, we update the cache for all of their contacts.

Since a single member who changes their contact information can require updating the contacts cache for hundreds or even thousands of other members, we rely upon prioritized tasks in our offline queue system. Going Custom Searching. Reverse autocomplete. Back to my homepage This is a proposal for a small improvement on the autocomplete feature, commonly found in many applications. To my knowledge, it hasn't been described or implemented elsewhere. If you know otherwise, or have some comments or suggestions, drop me a line to the address below. [note] 1. 1. Autocomplete is a well-known user interface feature implemented in many different kinds of software: There are many variations in the implementation details of this feature: User interface: can be a drop-down box (1, 3, 4, 6, 7) or text inserted directly, in many cases with auto-selection (1 for some older browsers, 2, 5) Exact/fuzzy match: in case of word processors or web queries it is often useful to allow for fuzzy matches, thus providing spell correction (for example in Google Suggest, if I enter "amrei", it offers to correct "American 2.

Let's see some examples of this behaviour: 3. Example: "United | America" 4. This example implementation in javascript is based on AutoSuggest v1.0. Home.