google/guice — pull request #880 by stephanenicolas (2014-11-11 17:41:15+00:00)
Title: Blender PR

Hi Guice Team,

as discussed on the mailing list, @emmby and I would like to introduce a new annotation processor to Guice to boost its performances. Mike authored RoboGuice and I contribute to it actively too. Our focus is to make guice more efficient so that it can remain an interesting DI option on Android.

We currently use Blender (indeed an extension called RoboBlender) in RG 3 now and it works fine (though we have a few minor issues). According to us, this extension is close to be production ready. Nevertheless, we feel like some points could be enhanced to better match the quality standards of Guice itself.

So, we submit this PR in order to start talking with the Guice team and see if you guys are interested by this technology. We already got plans to push Guice performance further...

Please note : we couldn't squash all changes as we had a lot of merges to current guice state. Sorry about that.

Roughly speaking, this PR :
* adds a new module named blender : an annotation processor
* the annotation processor scans all files to compile in order to retrieve injection points and create an annotation database. The injection points will be passed to guice, avoiding a lot of reflection at runtime.
* annotation databases are created as code, this can look a bit ugly, but it would be very difficult to use a binary file in such a way that both Java and Android could use it easily ; Android resource loading being quite specific.
* the annotation database is also used to discard unnecessary bindings (it can sound strange but RoboGuice actually binds a lot of things automatically to make Android development more easy, and we want to keep only the bindings used in an application).
* we also introduced a hierarchy traversal filter to prune the classes to scan for injection points at runtime. Each scan is costly, so we offer to stop scanning when finding some given ancestor classes. For instance, in RG based apps, all classes that use injections will inherit from RG classes, and we can stop scanning when we have processed them, no need to go further up than RG classes (no need to scan their parents, they don't contain injection points..).

You can find much more details in the slides :
https://speakerdeck.com/stephanenicolas/blender-boosting-guice-with-annotation-processing

Thanks for your work on Guice,
Stéphane for the RG team.