On Sun, 2009-01-18 at 14:41 +0100, Jan-Kees van Andel wrote:
> 2009/1/11 Matthias Wessendorf <mat...@apache.org>:
> > On Sun, Jan 11, 2009 at 4:46 AM, Mario Ivankovits <ma...@ops.co.at> wrote:
> >
> > ;-) I really hate to wait on the boot-up.
> > :-)
> >
> > --
> > Matthias Wessendorf
> >
> > blog: http://matthiaswessendorf.wordpress.com/
> > sessions: http://www.slideshare.net/mwessendorf
> > twitter: http://twitter.com/mwessendorf
> >
> 
> Last week I've been playing around with a (non-Reflection) classpath
> scanner of my own. It's actually not that hard to write (if you have
> the class file format specification somewhere for reference) and my
> experience until now is that it's much faster than using Reflection.
> 
> I have a test webapp which I deploy on Tomcat. This webapp contains
> about 650 classes.
> 
> With reflection, it takes about 1500ms to read them all, with my
> custom home brewn scanner, it only takes between 300ms and 350ms.
> The only performance tweak I have made was a BufferedInputStream, so
> I'm sure there is enough room for other improvements (maybe some
> fork-join algorithm to support parallelism).
> I haven't really tested memory footprint yet, but 650 classes is still
> not that much.
> 
> Current status (I do this in spare time ;-)):
> - Expose the parsed classes in a developer-friendly format, instead of
> the raw class file format. (it's like a lite version of the Reflection
> API, to keep it fast).
> - Read classes in jars.
> - Test for possible ClassLoader issues.
> - Allow users to specify their own searchpaths.
> - Package filtering.
> - Search/filter API to allow the developer to only load classes that
> implement some interface or are tagged with an annotation.
> 
> If I'm satisfied with the results, we can see if it may fit into
> MyFaces (or maybe a reusable utility, since there are other projects
> that need to scan for annotations).
> It's not that much code and this way there is no need for an
> additional dependency.
> 

That sounds great.

What is your general approach? Just read in the class as byte[], then
use the class-file-format rules to get to the annotations sections on
the class and the methods? From my quick scan of the classfile spec it
seemed reasonably easy to do that...

I'd be interested to know the actual requirements that MyFaces has for
such a scanner. For example, does it ever need to look for annotations
on methods when the class itself is not annotated?

Your comment about "expose parsed classes" seems to imply that you are
providing some kind of DOM-style API. I would have thought that a
SAX-style API would be better, ie various bits of code interested in
annotations registers callbacks for annotations it cares about with the
"scanner". Then the scanner scans all jars in the classpath and when
something is found that matches a "registered" annotation, then it
invokes the appropriate callback. That approach would minimise memory
usage, and I can't see where we would need anything dom-like...

Regards,
Simon

Reply via email to