Faster Code Completion

The python code completion engine in MonoDevelop is now much faster. It's was a simple fix and one that I think gets overlooked too often in these "dynamic" days.

Thankfully, python makes it easy to index information based on a fully-qualified name. Everything can basically be represented in package format such as "xml.etree.ElementTree.ElementTree.isinstance". Of course, the simplest way to find anything matching a prefix is to just use the SQL LIKE operator. It's fast enough, and gets the job done.

Now, where it gets tricky. I need to be able to limit the result set to only show items that do not have a '.' after the prefix of my LIKE query. SQLite does not have a built in function to help us do this, and if it did, it would be the wrong way.

Since the data in each row will never change (other than a complete row update) we know that we have the ability to safely pre-compute information about the row. Remember how the data is in a package format? Each of those '.' indicate a new depth which we can use for indexing.

So the simple fix is to pre-compute the number of '.' in the fully qualified name and simply add your desired depth to the query. Less data returned in your data reader means less memory allocated by the VM, less memory to free and less memory fragmentation. Good times.

The new field will mean your completion database needs to be upgraded. No fear though, that's done for you automatically.

-- Christian Hergert 2009-08-28

Back to Index