Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Guice Performance on Android

As a Java developer I've become accustomed to having dependency injection available in applications. For Android though, I am especially wary of performance. What are the performance implications for using Guice in an Android app? I assume there is some overhead, but is it significant enough that I should avoid using Guice?

My use of it would likely just be to inject a few shared objects into various activities.

like image 912
user605331 Avatar asked Feb 21 '11 15:02

user605331


People also ask

Why is dagger faster than Guice?

Supposedly faster than Guice, because Dagger works by generating code up-front, whereas Guice uses Reflection at runtime.

Which is better Guice or Spring?

Spring allows you to omit the @Autowired annotation when there's only one constructor. Guice allows binding to a Provider, as well as injecting a Provider of your class, even when your class has no Provider binding.

Is dagger better than Guice?

Guice is base on reflection, while Dagger is generating extra code during compile-time; reflection is much slower than the pre-generated code. Dagger is often used in Android development(reflection is even slower in Android) Dagger has simpler APIs, and the stacktrace is easier to understand.

Does Google use Guice?

Guice is an open source, Java-based dependency injection framework. It is quiet lightweight and is actively developed/managed by Google.


2 Answers

I would avoid using DI in android as google suggests: http://developer.android.com/training/articles/memory.html#DependencyInjection

Dagger solves some timing problems but still wastes memory for no real benefit.

like image 178
Edmund Chang Avatar answered Sep 17 '22 17:09

Edmund Chang


As of version 3, Guice caches reflective objects to improve performance. There's at least one bug out against dalvik to make annotation lookups faster, but the current performance is workable.

like image 20
Jesse Wilson Avatar answered Sep 19 '22 17:09

Jesse Wilson