the blog
Back to -Blog

Flex IntelliSense with Amethyst - the need for speed!

Doing introspection the fast way
by Dermot Hogan
Monday 19 January 2009.

When the great physicist Richard Feynman died, it was said that “There were two ways to solve physics problems. One was to use mathematics, the other was to ask Feynman.” Now that’s an obituary to die for! To stretch the point (just a little) – there are two ways to do IntelliSense in ActionScript: one is to ask Flash, the other is to do it yourself.

So which did we choose...?

The technique of asking Flash (or more correctly the Adobe Virtual Machine or AVM) is called “introspection” and its equivalent in .NET is “reflection". This involves querying the AVM at runtime about the methods and variables contained in a class, say, and displaying the results. It’s useful sometimes if you are trying to find out what’s going on, or are going to call some method dynamically.

The problem with introspection is that it’s slow. Seriously slooow.

It’s also not very flexible. For IntelliSense, you have to start up an AVM (the Flash player usually) load the libraries or programs that you are interested in, get all the information back (don’t think of doing it ’on the fly’: you will notice the delay after a dot) and keep it all for future use. Even though you will, in practice, only ever use a tiny fraction of it.

Well, that didn’t seem to be the right approach at all, so we wrote our own introspection system. Which is, naturally, seriously fast.

The downside is that it is a whole lot more complicated and difficult to debug. So to help debug it, I turned to a part of Visual Studio that I’ve never used before – the Object Browser. Incidentally, even though we programmed an ActionScript Object Browser mainly for our own debugging purposes we will also be adding it to Amethyst, probably in the next beta release.

The Object Browser allows you to view all classes and objects available to your program, whether you use them or not. Now, in all the years I’ve been using Visual Studio, I’ve never, ever used this feature. Still, your mileage may vary, and no doubt some people would consider it an indispensible tool. And it turns out that it is – if you are debugging introspection!

I’ll demonstrate this by creating a simple test solution (note the Test1 library in the References section):

...and here’s a part of a class:

...and here’s what it looks like in the Object Browser. This tells me quickly that my introspection is the same as the AVM’s version.

Finally, here’s the full scale version with the three main libraries added:

And the speed? Loading the libraries required for IntelliSense is about 40 times faster than using the standard AVM introspection system. That’s only the start: custom introspection opens up a whole new area for ActionScript tools which we’ll talk about in the future.

Next week, I’ll describe how we handle import statements using SmartTags.

Bookmark and Share   Keywords:  Amethyst  IntelliSense
© SapphireSteel Software 2014